there is a case i have whereby a df read from csv and then written to table includes space for certain cols.
here is a portion of the csv referenced as 'filename' below:
id, l, s
1,a,ay
2,b,bee
3,c,see
imports and sqlite connection:
import pandas as pd
import sqlite3
conn = sqlite3.connect('path_to_db')
c = conn.cursor()
then when running this (left out the header option as it is inferred to be 0 i believe):
>>> df = pd.read_csv('filename')
>>> df
id l s
0 1 a ay
1 2 b bee
2 3 c see
this is the part where i hope there is to be a fix once inserted...
>>> df.to_sql('table1', conn, if_exists='append', index=False)
so after checking for the table created, it included a space for col 2-3, based on running this:
>>> for items in c.execute('select * from sqlite_master where type="table" and name="table1"'):
... print(items)
...
('table', 'table1', 'table1', 101, 'CREATE TABLE "table1" (\n"id" INTEGER,\n " l" TEXT,\n " s" TEXT\n)')
my question is there a way to tell the to_sql
function to ignore that?