0

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?

2
  • Please paste the first 5 lines of .dat file here for inspection. Commented Jul 26, 2019 at 23:14
  • That is already a comma separated file, isn't it? Try sep=','... Commented Jul 26, 2019 at 23:16

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

and specify column names with: names = ['C1','C2','C3','C4','C5','C6','C7'], etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.