在尝试添加pandas数据帧时,sqlite3表没有更新



我正在尝试将Pandas数据帧添加到Django项目中的sqlite3表中。然而,当我尝试将其添加到表中时,控制台中不会显示任何更新和错误。作为参考,我的代码开头正确格式化了csv文件中的日期,然后我试图将其添加到一个名为"daos_transaction"的空表中,该表具有相同的属性"from_address"、"to_address"、"date_time"one_answers"amount"。

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

我终于弄明白了。这是因为我必须设置索引=错误

最新更新