Attempting to upload a bunch of csv's to a database. The csvs are not necesarily always separated by a comma so I used a regular expression to ensure the correct delimiters are used. I then added the
error_bad_lines=False
in order to handle CParserError: Error tokenizing data. C error: Expected 3 fields in line 127, saw 4 which resulted in me getting this error
ValueError: Falling back to the 'python' engine because the 'c' engine does not support regex separators, but this causes 'error_bad_lines' to be ignored as it is not supported by the 'python' engine.
for the following code
Is there a workaround?
import psycopg2
import pandas as pd
import sqlalchemy as sa
csvList = []
tableList = []
filenames = find_csv_filenames(directory)
for name in filenames:
lhs, rhs = str(name).split(".", 1)
print name
dataRaw = pd.read_csv(name,sep=";|,",chunksize=5000000, error_bad_lines=False)
for chunk in dataRaw:
chunk.to_sql(name = str(lhs),if_exists='append',con=con)
;to,with pythonre.subor linuxsedfor example.