Sample DF(1 column without header name):
vers 2.1.0
info days 6
info x a
info y b
Here is my code and error message:
df = pd.read_csv("64881_info.csv")
ParserError: Error tokenizing data. C error
I tried to fix:
import pandas as pd
df = pd.read_csv("64881_info.csv", error_bad_lines=False)
It works but column header name shift right by next. Row indexing is not showing also after reading the csv file. How can I fix this?
Output df:
vers 2.1.0
info days 6
info x a
info y b
CodePudding user response:
You could try to just skip the bad lines if you don't think there are too many:
df= pd.read_csv('64881_info.csv', on_bad_lines='skip')
CodePudding user response:
After resetting row indexing, it works!
df = df.reset_index()
output:
index vers 2.1.0
0 info days 6
1 info x a
2 info y b