Reputation: 243
I have imported a csv file into SQL Server with python but it is automatically inserting an index column as the first column. I have looked at other questions on SO regarding this issue and have tried things like index_col=false but the index still appears my code is as follows
from sqlalchemy import create_engine
import pandas as pd
engine = create_engine('mssql+pyodbc://'+UID+':'+PWD+'@'+DATABASE)
data = pd.read_csv(r'C:\Users\user\file.txt', chunksize=10000,index_col = False)
for i in data:
i.to_sql('table1', engine, if_exists='replace')
Upvotes: 0
Views: 329
Reputation: 911
I think you need to add the index = False
parameter to the to_sql
method:
for i in data:
i.to_sql('table1', engine, if_exists='replace', index=False)
Upvotes: 1