【问题标题】:How to index a PyArrow Table?如何索引 PyArrow 表?
【发布时间】:2020-10-31 16:57:33
【问题描述】:

我目前在我的机器学习模型中使用 Arrow 从 Parquet 读取数据。目前我正试图弄清楚如何从箭头表中获取某些记录。我看到箭头表有一个“Take”api,但我不知道如何使用它。我尝试传入一个 int 索引,但是当我尝试这样做时,我得到了以下异常:

Got unexpected argument type <class 'int'> for compute function

有人知道如何从箭头表中读取记录吗?

【问题讨论】:

    标签: pyarrow apache-arrow


    【解决方案1】:

    pyarrow Table 的 take() 方法需要类似数组的索引(而不是单个整数索引):

    >>> import pyarrow as pa
    >>> table = pa.table({'a': range(5)})
    >>> table.to_pandas()
       a
    0  0
    1  1
    2  2
    3  3
    4  4
    
    >>> table.take([0, 2]).to_pandas()
       a
    0  0
    1  2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      • 2022-08-10
      • 2018-11-03
      • 1970-01-01
      • 2020-01-11
      • 2021-01-10
      相关资源
      最近更新 更多