Construct pandas dataframe from a .fits file
Note: the second option with Table is better for most cases, since the way FITS files store data is big-endian, which can cause problems when reading into a DataFrame object which is little-endian. See https://github.com/astropy/astropy/issues/1156
According to what you have in your question and the astropy docs (http://docs.astropy.org/en/stable/io/fits/), it looks like you just need to do:
from astropy.io import fits
import pandas
with fits.open('datafile') as data:
df = pandas.DataFrame(data[0].data)
Edit:
I don't have much experience we astropy, but other have mentioned that you can read the fits files into a Table
object, which has a to_pandas()
method:
from astropy.table import Table
dat = Table.read('datafile', format='fits')
df = dat.to_pandas()
Might be worth investigating.
http://docs.astropy.org/en/latest/table/pandas.html