I am trying to read a .txt
file which contains string entries using pandas
. Different rows in this file have different number of columns. The file can be found here.
This is how I am trying to read the file.
pd.read_csv('file.txt', sep=r'\s+', header=None).values[:,1:].astype('<U100')
I get the following error when I use the above method to read the file:
ParserError: Error tokenizing data. C error: Expected 82 fields in line 4, saw 85
I read this Stackoverflow post. And, I tried this method now:
pd.read_csv('file.txt', error_bad_lines=False, sep=r'\s+', header=None).values[:,1:].astype('<U100')
The above method doesn't give any errors, but now multiple rows are being skipped during the reading of the file. Is there any way in which I can read the aforementioned file fully (all rows) without errors?