0

假设我有一个名为“my_data.json”的 json 文件,如下所示。

{"a": [1, 2], "b": {"c": true, "d": "1991-02-03"}}
{"a": [3, 4, 5], "b": {"c": false, "d": "2019-04-01"}}

如果我需要基于属性 d 进行连接操作,我可以直接从箭头结构中进行吗?(或者是否有任何有效的替代方案?)还有 json 格式的嵌套属性在以箭头格式转换后如何映射到缓冲区?

>>> table = json.read_json("my_data.json")
>>> table
pyarrow.Table
a: list<item: int64>
  child 0, item: int64
b: struct<c: bool, d: timestamp[s]>
  child 0, c: bool
  child 1, d: timestamp[s]
>>> table.to_pandas()
           a                                       b
0     [1, 2]   {'c': True, 'd': 1991-02-03 00:00:00}
1  [3, 4, 5]  {'c': False, 'd': 2019-04-01 00:00:00}
4

1 回答 1

0

您可以flatten在将其转换为熊猫之前将该表:https ://arrow.apache.org/docs/python/generated/pyarrow.Table.html#pyarrow.Table.flatten

>>> table.flatten().to_pandas()
           a    b.c        b.d
0     [1, 2]   True 1991-02-03
1  [3, 4, 5]  False 2019-04-01

然后你可以加入列b.db.c

于 2020-04-02T09:39:14.137 回答