gpt4 book ai didi

pandas - 什么是 pyarrow 表?它会取代 pandas 数据框吗?

转载 作者:行者123 更新时间:2023-12-02 20:13:46 29 4
gpt4 key购买 nike

我尝试阅读文档,但仍然很困惑。 pyarrow 表能够执行 groupby 和所有精彩的 pandas 功能吗?

import pyarrow as pa
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3]})
table = pa.Table.from_pandas(df)

但现在是虎头蛇尾:

table["a"]
# ---------------------------------------------------------------------------
# TypeError Traceback (most recent call last)
# <ipython-input-18-fb884245e2de> in <module>()
# ----> 1 table["a"]
# table.pxi in pyarrow.lib.Table.__getitem__()
# TypeError: an integer is required
table[0]
# <pyarrow.lib.Column object at 0x111306330>
# chunk 0: <pyarrow.lib.Int64Array object at 0x11728d1d8>
# [
# 1,
# 2,
# 3
# ]

c = table[0]
c[c>2]
# ---------------------------------------------------------------------------
# TypeError Traceback (most recent call last)
# <ipython-input-16-cc54312229de> in <module>()
# ----> 1 c[c>2]
#
# TypeError: '>' not supported between instances of 'pyarrow.lib.Column' and 'int'

pyarrow 是一个更适合 pandas 内部的库吗?

最佳答案

是的,pyarrow 是一个用于构建数据框架内部结构(和其他数据处理应用程序)的库。它不是像 pandas 这样的最终用户库。如果您想进一步讨论,请在 Apache Arrow 邮件列表上留言。

关于pandas - 什么是 pyarrow 表?它会取代 pandas 数据框吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52873072/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com