python - Group_by 不适用于具有 mixin 列的表 [Astropy、Table]

标签 python mixins astropy

我正在尝试运行此代码:

from astropy.table import Table
from astroquery.nasa_exoplanet_archive import NasaExoplanetArchive

exoplanets = NasaExoplanetArchive.get_confirmed_planets_table()
df=exoplanets.group_by('pl_orbsmax')
print(df)

并得到错误:

NotImplementedError: group_by not available for tables with mixin columns

我想简单地根据特定列中的条目提取数据。如何将此表转换为可以使用“group_by”的格式?

我试图将列限制为几个我很确定不是混合的列,例如:

subset=exoplanets['pl_discmethod','pl_orbsmax', 'pl_bmassj', 'st_mass']

但遇到了同样的错误。我尝试转换为 pandas,但这也不起作用。

最佳答案

mixin 列的分组是从 astropy 3.1 开始实现的:

In [3]: t = Table([[1,2], Time([1,2], format='cxcsec')], names=['x', 'time'])

In [4]: tg = t.group_by('x')

In [5]: tg.groups[1]
Out[5]: 
<Table length=1>
  x         time      
int64      object     
----- ----------------
    2 2.00000000000351

顺便说一句,您可以使用 has_mixin_columns 属性明确检查 mixin 列:

In [7]: t.has_mixin_columns
Out[7]: True

关于python - Group_by 不适用于具有 mixin 列的表 [Astropy、Table],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54000694/

相关文章:

python - Python 中带有文本数据的 MultiOutputClassifier

python - 'pip==9.0.1' 分布未找到,应用程序需要

python - 在 Python 单元测试和主代码中访问资源文件

python - 在 Python 中设置只读属性?

c++ - 如何在 C++ 中表示基本的 Mixin 行为

scala - scala 编译器可以在混合时强制实现抽象特征方法吗?

python - astropy.io.fits 从具有多个 HDU 的大型拟合文件中读取行

python - 使用 astropy.fits 和 numpy 对 SWIFT 拟合图像应用重合校正

haskell - 如何在 Haskell 中建模 mixins/多个接口(interface)?

fits - 在 astropy.io.fits 中为 BinTableHDU 数据添加标签