首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pyarrow将列添加到pyarrow表

pyarrow将列添加到pyarrow表
EN

Stack Overflow用户
提问于 2020-08-11 11:44:54
回答 1查看 1.5K关注 0票数 2

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

代码语言:javascript
复制
 list_ = ['IT'] * 6132
 final_table.append_column('COUNTRY_ID', list_)

但我得到了以下错误ArrowInvalid:添加的列的长度必须与表的长度匹配。预期长度为6132,但实际长度为12264

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-11 16:40:01

根据documentation的说法

代码语言:javascript
复制
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。为了避免混淆,您应该传递一个箭头数组

代码语言:javascript
复制
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()))
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63351189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档