This is my code to open file:
df = pd.read_csv(path_df, delimiter='|')
I get error: Error tokenizing data. C error: Expected 5 fields in line 13571, saw 6
When I check this particular line, I see that there was a misprint and there were 3 signs "|||" instead of one. I would prefer treat double and triple signs as one. Probably, there is other solution.
How can I solve this problem?
Use regex separator [|]+ - one or more |:
import pandas as pd
temp=u"""a|b|c
ss|||s|s
t|g|e"""
#after testing replace 'pd.compat.StringIO(temp)' to 'filename.csv'
df = pd.read_csv(pd.compat.StringIO(temp), sep="[|]+",engine='python')
print (df)
a b c
0 ss s s
1 t g e
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With