0

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

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.