簡體   English   中英

嘗試添加 pandas dataframe 時 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM