gpt4 book ai didi

python - pyarrow 将列添加到 pyarrow 表

转载 作者:行者123 更新时间:2023-12-02 02:42:23 28 4
gpt4 key购买 nike

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

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

但我收到以下错误 ArrowInvalid:添加的列的长度必须与表的长度匹配。期望长度 6132 但得到长度 12264

最佳答案

根据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 假设您正在提供一个数组列表。为避免混淆,您应该改为传递箭头数组

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()))

关于python - pyarrow 将列添加到 pyarrow 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63351189/

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