file written by df.to_csv cannot be read by pd.read_csv

Viewed 706

I have a dataframe I read from json, process, and save to csv. The df looks fine in terms of shape and df.head(), tail look fine. I write to a csv then read and get an error -

df = get_json(params)        
df.to_csv(f'fname.csv')
testdf = pd.read_csv(f'fname.csv')

ParserError: Error tokenizing data. C error: Buffer overflow caught - possible malformed input file.

Is there some 'careful write' I should be doing?

2 Answers

As per my experience with this issue, there was some problem with the default engine and doing this helped me:

df.read_csv('input.csv', engine = 'python')
Related