【发布时间】:2020-04-02 22:54:09
【问题描述】:
我正在使用 astropy 来操作 FITS 表,我想删除所有包含 nan 的行。
使用存储在mytable 中的拟合表,我尝试了以下操作
data = np.lib.recfunctions.structured_to_unstructured(np.array(mytable))
idx = []
for i, line in enumerate(data):
for e in line:
if e !=e:
idx.append(i)
data = Table([data[i] for i in range(len(data)) if i not in idx])
这似乎有效,但相当笨重。有没有更 Pythonic 的方式来做到这一点?
如果该行中的元素之一是nan,我想删除整行。 This question 不同,因为它是关于删除单个元素。
【问题讨论】:
标签: python-3.x astropy