0

I am reading a table from my sql server with Pandas such as

df= pd.read_sql('table1', engine)

where engine is my pyodbc connection and then again I am pushing it to sql server

df.to_sql('table2', engine, if_exists='replace')

which gives me an error

ValueError: duplicate name in index/columns: cannot insert level_0, already exists

and when I try to drop the column, it gave me some another error, which is anyways not an efficient way. I tried this as well, which also didn't work

 df= df.reset_index(drop=True)

Every help will be important

2
  • 2
    try index=Flase while wrting to_sql because index values should be unique. Commented Aug 9, 2016 at 13:44
  • It def works, so silly of me, If you want to post an answer, I will accept it as the answer. Thank you so much! Commented Aug 9, 2016 at 13:50

1 Answer 1

7

Set index=Flase while writing to_sql because index values should be unique.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.