2

I am learning to use pandas and sqlite together. The idea is to read a pandas DataFrame, modify it, and create a sqlite database.

this is my code :

import sqlite3

# create my database
conn = sqlite3.connect('my_db.db')
cursor = conn.cursor()

# create a DF from csv file 
my_df = pd.read_csv('my_csv_file.csv', sep = '\t')

# this DF contains 72 columns, called VN[REAL], where N is between 0 and 71. The values are floats.

# create a list concatenating two columns 
my_list = list(my_df['V1[REAL]']
my_list.append(list(my_df['V2[REAL]'])

df2 = pd.DataFrame(my_list)
df2.to_sql("Values", conn, index=False, dtype='float')

and I get the error :

sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

What could be the source of the error ?

  • You need column names in df2. Right now it reads numeric values, 0, 1, 2,.. And use SQLAlchemy for `to_sql`. – Parfait Nov 30 '17 at 17:34

1 Answers1

-1

I think you need to scape character the brackets []

A_emperio
  • 276
  • 2
  • 14