jupyter --InternalError: (pymysql.err.InternalError) (1054, "Unknown column 'index' in 'field list'")

0

I have a code in jupyter that what I want to do is insert the bd, it works well with the example that I have commented, but when doing it with the real csv, I deployed an error.

   import pandas as pd 
    df = pd.read_csv('4763.csv',header=[2],delimiter=";")
    df

from sqlalchemy import create_engine
#df = pd.DataFrame({'name' : ['User 1', 'User 2', 'User 3']})
engine = create_engine("mysql+pymysql://{user}:{pw}@localhost/{db}"
                       .format(user="root",
                               pw="",
                               db="remu2"))
df.to_sql(con=engine, name='csv',if_exists='append')

this is the error

InternalError: (1054, "Unknown column 'index' in 'field list'")

The above exception was the direct cause of the following exception:

InternalError                             Traceback (most recent call last)
    
asked by user3333557 26.06.2018 в 21:07
source

1 answer

0

Pandas automatically creates an index for you. df = df.drop (columns = 'index') eliminates it or index = False when creating the dataframe

    
answered by 26.06.2018 в 22:06