Skip to content

pd.read_fwf ignoring a space when reading space delimited file #23455

@paulvija

Description

@paulvija

Code Sample

temperature_lst=
   41485    177.40357149    -39.01654000   13.000    13.92  .0100  .2000    -1.02  .0100  .2000          
   41489    171.56518149    -42.94461000  743.000     7.29  .0100  .3333      .51  .0100  .3333        
df = pd.read_fwf('./temperature_lst',names=['agn','longt','lat','v1','v2','v3', 'v4','v5','v6', 'v7'])

df.tail()
agn       longt       lat     v1     v2    v3      v4    v5    v6      v7
41485  177.403571 -39.01654   13.0  13.92  0.01  0.2000  1.02  0.01  0.2000
41489  171.565181 -42.94461  743.0   7.29  0.01  0.3333  0.51  0.01  0.3333

Problem description

temperature_lst is a space delimited file, when using read_fwf to read this in to a dataframe some space is truncated in column 'v5'. This results in '-1.02' becoming just '1.02'.
Is this is a bug?

However, this works when 'widths' is defined. In my case, there are multiple files that are read in this way, so using 'widths' can be tedious.

 df = pd.read_fwf('./11068_temperature_anom.lst',names=['agn','longt','lat','v1','v2','v3', 'v4','v5',
    ...: 'v6', 'v7'], widths=[8,16,16,9,9,7,7,9,7,7])

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO DataIO issues that don't fit into a more specific label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions