[英]Pandas Dataframe Encoding Vector from ManyToMany Join Table in Sqlite3
[英]sqlite3 table is not updating when trying to add pandas dataframe
我正在尝试将 Pandas 数据框添加到我的 Django 项目中的 sqlite3 表中。 但是,当我尝试将其添加到表中时,控制台中不会打印任何更新和错误。 作为参考,我的代码开头正确格式化了 csv 文件中的日期,然后我尝试将其添加到一个名为 'daos_transaction' 的空表中,并具有相同的属性 'from_address'、'to_address'、'date_time' , 和“金额”。
import pandas as pd
import sqlite3
# Reads data from csv file
df = pd.read_csv("correct/path/to/csv/file")
# Formats the date
for dt in range(len(df['date_time'])):
no_t_string = df['date_time'][dt].replace('T', ' ')
clean_string = no_t_string.split('+')[0]
df['date_time'][dt] = clean_string
# Converts the column to a date time field
df['date_time'] = df['date_time'].astype('datetime64[ns]')
cnx = sqlite3.connect('correct/path/to/db')
df.to_sql('daos_transaction', cnx, if_exists='append')
我最终弄清楚了。 这是因为我必须设置 index=False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.