How do I read a fix width format text file in pandas

pandas.read_fwf() was added in pandas 0.7.3 (April 2012) to handle fixed-width files.

  1. API reference

  2. An example from other question


Wes answered me in an email. Cheers.

This is a fixed-width-format file (not delimited by commas or tabs as usual). I realize that pandas does not have a fixed-width reader like R does, though one can be fashioned very easily. I'll see what I can do. In the meantime if you can export the data in another format (like csv--truly comma separated) you'll be able to read it with read_csv. I suspect with some unix magic you can transform a FWF file into a CSV file.

I recommend following the issue on github as your e-mail is about to disappear from my inbox :)

https://github.com/pydata/pandas/issues/920

best, Wes

Tags:

Python

Pandas