Old-School Old-School - 1 year ago 188
Python Question

Construct pandas dataframe from a .fits file

I have a .fits file that contains data.

I would like to construct a pandas dataframe from this particular file but I don't know how to do it.

data = fits.open('datafile')


No. Name Type Cards Dimensions Format
0 PRIMARY PrimaryHDU 6 (12, 250000) float64




(250000, 12)

Answer Source

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
data = fits.open('datafile')
df = pandas.DataFrame(data[0].data)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download