Search code examples
pythonpandaspyfits

Conversion of a .fits file


I've got a .fits file and I want to read the data, unfortunately I'm not at all familiar with this format type. Is there a way to convert it to a table (.txt file?) so that I can work with it using pandas? I just found pyfits and read some of the documentation but it's a bit nebulous to me.

Thanks.


Solution

  • The pyfits getdata function returns an ndarray from the file:

    from pyfits import getdata
    data = getdata(file_name)
    

    then you can decide which slice(s) to put into your DataFrame(s).

    (These bnviewer slides [1] [2] seem like quite a nice primer.)