Reputation: 3282
I want to take this .dat file: Airline list and convert it into a readable CSV file. However, for some reason each time I do this:
df = pd.read_csv('/path/airlines.dat', sep='\s+', header=None, skiprows=1)
I get the following error:
ParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 3
Am I correctly reading this file? What am I doing wrong?
Upvotes: 0
Views: 232
Reputation: 10860
First try
df = pd.read_csv('/path/airlines.dat', header=None, skiprows=1)
please.
Results in my case in
pd.read_csv('/path/airlines.dat', header=None, skiprows=1).head()
# 0 1 ... 6 7
# 0 1 Private flight ... NaN Y
# 1 2 135 Airways ... United States N
# 2 3 1Time Airline ... South Africa Y
# 3 4 2 Sqn No 1 Elementary Flying Training School ... United Kingdom N
# 4 5 213 Flight Unit ... Russia N
# [5 rows x 8 columns]
Upvotes: 1