Sep-25-2021, 02:01 AM
(This post was last modified: Sep-25-2021, 02:01 AM by aliyesami.
Edit Reason: Added code tags
)
i have a simple csv file as follows :
the code is as follows minus DB connection details since connection is fine :
I am trying to load the csv using pandas data frames but if i dont put the header in csv as "id,name" it does not insert rows and throws "invalid identifier " error.
I want to load this csv file in the table without having to put a header .
please advise .The code and error are below.
Note: I have tried using header=None ,still doesnt work .
Note2: plz note that if I put the header Id,Name in the csv file the code works fine and loads the rows in the table.
see attached outputs for both cases , first one is without using the header clause and second case is using header clause.
Output:1,'sami'
2.'john',
3,'mary'
4,'peter'
and i have a table test(id, name
) the code is as follows minus DB connection details since connection is fine :
#df=pd.read_csv('test.csv',encoding= 'unicode_escape', header = None) df=pd.read_csv('test.csv',encoding= 'unicode_escape' ) print(df) df.shape df.info() df.to_sql('test', engine, index=False, if_exists='append')[/python]
I am trying to load the csv using pandas data frames but if i dont put the header in csv as "id,name" it does not insert rows and throws "invalid identifier " error.
I want to load this csv file in the table without having to put a header .
please advise .The code and error are below.
Note: I have tried using header=None ,still doesnt work .
Note2: plz note that if I put the header Id,Name in the csv file the code works fine and loads the rows in the table.
see attached outputs for both cases , first one is without using the header clause and second case is using header clause.
Attached Files

