sqlite3 table is not updating when trying to add pandas dataframe

Viewed 21

I am trying to add a Pandas data frame to a sqlite3 table in my Django project. However, when I try to add it to the table, nothing updates and no errors are printed in the console. For reference, the beginning of my code is correctly formatting the date in the csv file and then I am attempting to add it to an empty but existing table named 'daos_transaction' with the same attributes 'from_address', 'to_address', 'date_time', and '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')
1 Answers

I ended up figuring it out. It was because I had to set index=False

Related