【问题标题】:pyarrow add column to pyarrow tablepyarrow 将列添加到 pyarrow 表
【发布时间】:2020-08-11 16:40:01
【问题描述】:

我有一个形状为 6132,7 的 pyarrow 表名 final_table 我想在此表中添加列

 list_ = ['IT'] * 6132
 final_table.append_column('COUNTRY_ID', list_)

但我收到以下错误 ArrowInvalid: added column's length must match the table's length.预期长度为 6132,但长度为 12264

【问题讨论】:

    标签: python pyarrow


    【解决方案1】:

    根据documentation

    Append column at end of columns.
    
    Parameters
    field (str or Field) – If a string is passed then the type is deduced from the column data.
    
    column (Array, list of Array, or values coercible to arrays) – Column data.
    
    Returns
    pyarrow.Table – New table with the passed column added.
    

    我认为 pyarrow 假设您提供的是 list of Array。为避免混淆,您应该改为传递箭头数组

    col_a = pa.array([1, 2, 3], pa.int32())
    col_b = pa.array(["X", "Y", "Z"], pa.string())
    
    table = pa.Table.from_arrays(
        [col_a, col_b],
        schema=pa.schema([
            pa.field('a', col_a.type),
            pa.field('b', col_b.type),
        ])
    )
    
    table.append_column('COUNTRY_ID', pa.array(['IT'] * len(table), pa.string()))
    

    【讨论】:

      猜你喜欢
      • 2021-05-21
      • 2022-01-16
      • 2022-08-18
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      相关资源
      最近更新 更多