Truncated Beginning String Characters When Reading txt file to pandas

166 views Asked by At

I am trying to read a txt file to a pandas data using pandas.read_fwf. Here's my line of code:

klia_sepang = pd.read_fwf('KLIA_SEPANG.txt', sep='[ ]{1,}')

However, I'm finding out that all string of 100th decimal places will be truncated at the beginning. So a 791.0 becomes 91.0, 309.0 becomes 09.0, and so on. I'm not sure why this happens. I've tried adding parameters like colspecs and widths to no avail.

txt file

pandas data

1

There are 1 answers

0
Brainskan On

Looking at your text file, you probably want to use the widths or colspec parameters to define how to break up the file into columns. Or you might have success just letting read_fwf infer how to organize the columns of data.

I don't think passing "sep" with those characters is helping, and it may be confusing the parser.