Python Forum
Error when inserting CSV file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when inserting CSV file
#2
if it is indeed a csv file, you should open and read using pandas package. Code would look like (replaced f with csvf, single letter names shouldn't be used, they mean nothing to whoever (other than the author) reads them, especially this one because starting with python 3.6, f stands for f-string and may be misinterpreted).

You should make sure values for delimiter and quotechar are correct for your file
only use next(fp) if you want to eliminate first row, which is the header and is useful for SQL insert

import pandas

with open 'EMPLOYEE.csv', 'r') as csvf:
    df = pandas.read_csv(csvf)
    df.to_sql('employee', conn, if_exists='append', index=False)
Reply


Messages In This Thread
Error when inserting CSV file - by vndywarhol - Sep-16-2018, 10:09 AM
RE: Error when inserting CSV file - by Larz60+ - Sep-16-2018, 10:43 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020