1

I want to read a text file as a pd dataframe, but i don't know which delimiter should i choose to read the data correctly.

Data in the text file looks like this :

enter image description here


USAF   WBAN  STATIONNAME   CTRY ST CALL  LAT     LON      ELEV(M) BEGIN    END

007018 99999 WXPOD 7018                  +00.000 +000.000 +7018.0 20110309 20130730

I need to have "STATIONNAME" in one column but what i choose delimiter = ' ' , data in that column will be separated each word in a column and all the data in the file will be messed up.

Any suggestion please !

1

2 Answers 2

1

We can't tell for sure from the picture, but the data may be tab-delimited. If so, you can read the file like this:

df = pd.read_csv('<filename>', sep='\t')
Sign up to request clarification or add additional context in comments.

Comments

0

Thank you, I solved the problem using pandas.read_fwf(path,compression='infer'). This command is used to read fixed-width-files.

We can also specify the header using pandas.read_fwf(path,compression='infer',names=header).

Comments

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.