pythonpandasdata-processingread-fwf

Pandas read_fwf doesn't read the last digital each row


I have a .rpt file that has two columns, like this:

           A column            B column
          990.E-03            -2.73654E-03
         995.E-03            -2.75347E-03
          1.                -2.76635E-03

And when I use pd.read_fwf to read the table, df = pd.read_fwf('myfile.rpt', delimiter=" ") it neglect the last digit.

For example, the table in my .rpt file:

Column A Column B
990.E-03 -2.73654E-03
960.E-03 -2.6323E-03

will be converted to this table in df:

Column A Column B
0.99 -2.73654
0.96 -0.0026323

It seems that when the function will neglect of the second column when the that cell has more than 11 letters, and in my cases that digit the magnitude which is the most important. Looking forward to your solution.


Solution

  • As alternative, you can read your RPT file with read_table or read_csv and define sep='\s+' as parameter.

    # or df.read_csv
    df.read_table('myfile.rpt', sep='\s+')