RUN YR AP15 PMTE RSPC NPPC NEE SSF PRK QDRN
0 1 2008 4.53 0.04 641.21 16.8 624.41 328.66 2114.51 0
1 1 2009 3.17 0.03 1428.30 0.0 1428.30 23.58 3.20 0
2 1 2010 6.20 0.03 1124.97 0.0 1124.97 23.94 18.45 0
3 1 2011 5.38 0.02 857.76 0.0 857.76 28.40 42.54 0
4 1 2012 7.32 0.02 831.42 0.0 831.42 23.92 25.58 0
I am storing the above dataframe in a sqlite db as follows:
from sqlalchemy import create_engine
db_name = 'sqlite:///C:\\tmp.db'
engine = create_engine(db_name)
df.to_sql(db_name, engine, if_exists='append')
However, I get an error when I try to read it back:
df = pandas.read_sql_table(db_name, 'sqlite:///C:\\tmp.db')
ValueError: Table sqlite:///C:tmp.db not found
The tmp.db is created, since I can see it in SQLite studio. What am I doing wrong?
SQLite via Pandas One cool thing you can do is use both SQLite and Pandas. Pandas has a read_sql_query method that will allow you to return the data as a Pandas dataframe. From there, you can more easily manipulate the data in Pandas.
Specifying a string URL instead of an engine object is only added in the recently released 0.17.0. So you need to first construct the engine object:
engine = sqlalchemy.create_engine('sqlite:///C:\\tmp.db')
df = pandas.read_sql_table(db_name, engine)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With