Error binding parameter 0 - probably unsupported type. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Error binding parameter 0 - probably unsupported type. (/thread-28408.html) |
Error binding parameter 0 - probably unsupported type. - illmattic - Jul-17-2020 Hoping I can get some help on this error: c.execute("INSERT INTO USMoneySupply (MonetaryBase, M1, M2) VALUES (?, ?, ?)", sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type. api_key = open('quandlapikey.txt', 'r').read() def data_extract(code): data = quandl.get(code, authtoken=api_key, collapse='monthly') data['Y/Y, (%)'] = data['Value'].pct_change(12)*100 return data m2 = data_extract('FRED/M2') m1 = data_extract('FRED/M1') mb = data_extract('FRED/BOGMBASEW') conn = sqlite3.connect('Database.db') c = conn.cursor() def create_table(): c.execute("CREATE TABLE IF NOT EXISTS USMoneySupply(MonetaryBase REAL, MonetaryBasePer REAL, M1 REAL, M1Per REAL, M2 REAL, M2Per REAL)") def data_entry(): mb_data = mb['Value'] mb_per = mb['Y/Y, (%)'] m1_data = m1['Value'] m1_per = m1['Y/Y, (%)'] m2_data = m2['Value'] m2_per = m2['Y/Y, (%)'] c.execute("INSERT INTO USMoneySupply (MonetaryBase, MonetaryBasePER, M1, M1Per, M2, M2Per) VALUES (?, ?, ?, ?, ?, ?)", (mb_data, mb_per, m1_data, m1_per, m2_data, m2_per)) conn.commit() create_table() data_entry() c.close() conn.close()Thank you. RE: Error binding parameter 0 - probably unsupported type. - Larz60+ - Jul-18-2020 please show the actual error traceback, complete and unaltered. It contains valuable debugging information. RE: Error binding parameter 0 - probably unsupported type. - illmattic - Jul-18-2020 Sorry about that. Is this better?
RE: Error binding parameter 0 - probably unsupported type. - Larz60+ - Jul-18-2020 It's complaining about the type of MonetaryBase (I believe), add just before insert statement: print(f"Type MonetaryBase: {type(MonetaryBase)}")What are the results? RE: Error binding parameter 0 - probably unsupported type. - illmattic - Jul-18-2020 print(f"Type MonetaryBase: {type(MonetaryBase)}")
RE: Error binding parameter 0 - probably unsupported type. - Yoriz - Jul-18-2020 It is the value of mb_data that you need to find out what it is
RE: Error binding parameter 0 - probably unsupported type. - illmattic - Jul-18-2020 (Jul-18-2020, 02:56 PM)Yoriz Wrote: It is the value of Like this: def data_entry(): mb_data = mb['Value'] mb_per = mb['Y/Y, (%)'] m1_data = m1['Value'] m1_per = m1['Y/Y, (%)'] m2_data = m2['Value'] m2_per = m2['Y/Y, (%)'] print(f"Type mb_data: {type(mb_data)}")
RE: Error binding parameter 0 - probably unsupported type. - illmattic - Jul-18-2020 I found a different way to achieve the desired result: api_key = open('quandlapikey.txt', 'r').read() def data_extract(code, column_name): data = quandl.get(code, authtoken=api_key, start_date='2000-01-01', collapse='monthly',) data['Y/Y, (%)'] = data['Value'].pct_change(12)*100 data.rename(columns={'Value': column_name}, inplace=True) return data m2 = data_extract('FRED/M2','M1') m1 = data_extract('FRED/M1','M1') mb = data_extract('FRED/BOGMBASEW', 'Monetary Base') df_merged = [mb,m1,m2] df = reduce(lambda left,right: pd.merge(left,right,on='Date', how='outer'), df_merged).fillna('-') conn = sqlite3.connect('Database.db') c = conn.cursor() def data_entry(): df.to_sql('US Money Supply', conn, if_exists='replace') conn.commit() c.close() conn.close() data_entry()Here I get no errors and the output I wanted. |