I have a dataframe that looks like this:
df = pd.DataFrame(index= pd.date_range('2014-01-01', periods=10))
df['date'] = df.index.map(lambda x: x.strftime('%d-%m-%Y'))
df['date'] = df.index
df['profit']= rand(10)
df['perf_period_id']=2
also have a sqlite3 db with a table called fee_profit
fee_profit has 4 fields:
- id - integer - primary key
- perf_period_id - integer
- date - date
- profit - real
When I try to write the dataframe to the database with (not showing db connection):
df.to_sql(name='fee_profit', index=False, con=db, if_exists='append')
I get the following code:
252 else:
253 data = [tuple(x) for x in frame.values.tolist()]
--> 254 cur.executemany(insert_query, data)
255
256
InterfaceError: Error binding parameter 0 - probably unsupported type.
Not passing the primary key (could this be the problem?) I have jumbled the table around and it is definitely looks like the date that is the problem. Have tried various combinations of passing the date in index and also is string, bit nothing works.
Any idea where I am going wrong. Cannot find examples of using this method anywhere.
using Pandas 0.13.1 and sqlite 3 2.6.0. Database was created through django 1.6 model