【问题标题】:pyarrow get int from pyarrow int array based on indexpyarrow 根据索引从 pyarrow int 数组中获取 int
【发布时间】:2021-08-08 18:52:06
【问题描述】:

我正面临 pyarrow 这个非常烦人的问题,它没有给我列表/数组中的 int :((

所以,我有:

x=pa.array([1,2,3])
x[0]
<pyarrow.Int64Scalar: 1>

我只想要1 回来!我试过了:

>>> x[0].as_py
<built-in method as_py of pyarrow.lib.Int64Scalar object at 0x7f62a3abc0c0>

但是,当我对字符串执行此操作时,它会按预期工作:

>>> y=pa.array(['1','2','3'])
>>> str(y[0])
1

为什么这对 int 不起作用? :((

【问题讨论】:

    标签: python pyarrow


    【解决方案1】:

    因为as_py是一个方法,所以调用方法需要有括号:

    >>> x[0].as_py()
    1
    

    str(y[0]) 起作用的原因是因为__str__ 方法在将对象传递给str 函数时使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-07
      • 1970-01-01
      • 2018-11-03
      • 2018-09-05
      • 2017-01-19
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多