与Pandas套餐对接#
这个 pandas package是一个用于表状结构的高性能数据分析的包,它是对 Table
班在 astropy
.
为了在两个服务器之间交换数据 Table
类和 pandas.DataFrame
类(中的主要数据结构 pandas
)、 Table
类包括两个方法, to_pandas()
和 from_pandas()
。
例子#
为了演示,我们可以创建一个最小表:
>>> from astropy.table import Table
>>> t = Table()
>>> t['a'] = [1, 2, 3, 4]
>>> t['b'] = ['a', 'b', 'c', 'd']
然后,我们可以将其转换为 DataFrame
**
>>> df = t.to_pandas()
>>> df
a b
0 1 a
1 2 b
2 3 c
3 4 d
>>> type(df)
<class 'pandas.core.frame.DataFrame'>
还可以从 DataFrame
**
>>> t2 = Table.from_pandas(df)
>>> t2
<Table length=4>
a b
int64 string8
----- -------
1 a
2 b
3 c
4 d
往返的转换 pandas
注意事项如下: