[GitHub] hillaryhitch commented on issue #381: Allow users to import CSV as datasource

2017-08-24 Thread git
hillaryhitch commented on issue #381: Allow users to import CSV as datasource
URL: 
https://github.com/apache/incubator-superset/issues/381#issuecomment-324575569
 
 
   hey @timifasubathe method I use is using pandas to transform the
   data...all this is done on the server (back end), then I put the data in
   sqlite as a .db file...see below code that if you replicate you will easily
   import any csv, after you do thisthen go to superset data
   sources-databases and input 'sqlite///sites_4g.db' (in my example below I
   created a db with name sites_4g.db)
   
   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'
   
   On Thu, Aug 24, 2017 at 3:16 AM, timifasubaa 
   wrote:
   
   > Update: I'm now working on this issue, continuing from @SalehHindi
   >  's last commit to the csv-import branch.
   > When I run the code, I don't see any "Add CSV Table to Database" button.
   > Can you tell what I might be doing wrong?
   > You can look at the code I'm running on my fork (https://github.com/
   > timifasubaa/incubator-superset) with branch name import_csv.
   > Also, please post a snapshot of the new flow (e.g. the page with the new
   > button e.t.c.) .
   >
   > ?
   > You are receiving this because you commented.
   > Reply to this email directly, view it on GitHub
   > 
,
   > or mute the thread
   > 

   > .
   >
   
 

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


[GitHub] hillaryhitch commented on issue #381: Allow users to import CSV as datasource

2017-08-12 Thread git
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