hillaryhitch commented on issue #381: Allow users to import CSV as datasource
URL: 
https://github.com/apache/incubator-superset/issues/381#issuecomment-322020350
 
 
   import pandas as pd
   pdsites = pd.read_csv("site_data.csv")
   pdsites.columns
   
   
   def df2sqlite(dataframe, db_name = "import.sqlite", tbl_name = "import"):
   
       import sqlite3
       conn=sqlite3.connect(db_name)
       cur = conn.cursor()
   
       wildcards = ','.join(['?'] * len(dataframe.columns))
       data = [tuple(x) for x in dataframe.values]
   
       cur.execute("drop table if exists %s" % tbl_name)
   
       col_str = '"' + '","'.join(dataframe.columns) + '"'
       cur.execute("create table %s (%s)" % (tbl_name, col_str))
   
       cur.executemany("insert into %s values(%s)" % (tbl_name, wildcards), 
data)
   
       conn.commit()
       conn.close()
   
   df2sqlite(pdsites, db_name="sites_4g.db", tbl_name = "sites_data_4g")
   
   
   import sqlite3
   import pandas as pd
   # Create your connection.
   cnx = sqlite3.connect('sites_4g.db')
   
   df = pd.read_sql_query("SELECT * FROM sites_data_4g", cnx)
   df.head(5)
   
   ####Then go to superset data sources-databases and input 
'sqlite///sites_4g.db'
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to