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

后端 未结 4 1975
Happy的楠姐
Happy的楠姐 2020-12-07 01:16

I just got my hands on pandas and am figuring out how I can read a file. The file is from WRDS database and is the SP500 constituents list all the way back to 1960s. I check

4条回答
  •  暖寄归人
    2020-12-07 01:35

    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

提交回复
热议问题