【问题标题】:Pandas sqlite3: DataFrame.to_sql. "Error binding parameter 0 - probably unsupported type"Pandas sqlite3:DataFrame.to_sql。 “错误绑定参数 0 - 可能不受支持的类型”
【发布时间】:2017-11-30 11:42:51
【问题描述】:

我正在学习同时使用 pandas 和 sqlite。这个想法是读取一个 pandas DataFrame,修改它,然后创建一个 sqlite 数据库。

这是我的代码:

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')

我得到了错误:

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

错误的根源可能是什么?

【问题讨论】:

  • 您需要 df2 中的列名。现在它读取数值,0, 1, 2,.. 并使用 SQLAlchemy for to_sql

标签: python pandas sqlite pandas-to-sql


【解决方案1】:

我认为您需要在括号 [] 中转义字符

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    相关资源
    最近更新 更多