How to make a.fits.gz file into a pandas DataFrame 'ValueError: Big-endian buffer not supported on little-endian compiler'

How to make a.fits.gz file into a pandas DataFrame 'ValueError: Big-endian buffer not supported on little-endian compiler'

我有文件 '3dhst.v4.1.5.master.fits.gz',我想将其打开并制作成 DataFrame。我想从中选择列,然后将其与另一个 DataFrame 合并。我尝试了以下操作:

import astropy
from astropy.io import fits
master = fits.open('3dhst.v4.1.5.master.fits.gz')
masterdf = pd.DataFrame(master[1].data)
masterdf = masterdf[['grism_id' , 'field' , 'ra' , 'dec' , 'z_best', 'z_best_s' ,  'z_spec' , 
'z_peak_phot' , 'z_max_grism']]

我得到:

ValueError: Big-endian buffer not supported on little-endian compiler

这是我之前看到的有关此文件的错误消息,但仍然不明白为什么。 astropy 文档说 'The open() function will seamlessly open FITS files that have been compressed with gzip, bzip2 or pkzip. Note that in this context we are talking about a FITS file that has been compressed with one of these utilities (e.g., a .fits.gz file).' 如果我 运行 只是打开文件,我就不会出错。我还尝试使用以下方式打开文件:

with gzip.open('3dhst.v4.1.5.master.fits.gz') as f:
     master = fits.open(f)

这个 returns 是对 master[0].header 的空响应,所以这个方法失败了。

使用 Astropy 中的 Table class 可能是更好的选择,它有一种方法可以转换为 pandas DataFrame:

from astropy.table import Table
t = Table.read('3dhst.v4.1.5.master.fits.gz')
t = t[['grism_id' , 'field' , 'ra' , 'dec' , 'z_best', 'z_best_s' ,  'z_spec' , 'z_peak_phot' , 'z_max_grism']]
df = t.to_pandas()

https://docs.astropy.org/en/latest/table/pandas.html