【发布时间】:2021-05-05 01:25:53
【问题描述】:
我有以下熊猫数据框结构。有两 (2) 列:id 和 info(对象)
id info
0 14050000893760073 [{'route_id': '1', 'stop_id': '1'}, {'route_id': '2', 'stop_id': '2'}]
我想将此格式转换为以下格式:
id route_id stop_id
0 14050000893760073 1 1
1 14050000893760073 2 2
有什么想法吗?提前谢谢!
【问题讨论】:
-
df[['id']].join(pd.DataFrame(df['info'].explode().tolist())试试这个,因为我无法复制你的问题 -
@anky 我收到了这个错误:TypeError: object of type 'float' has no len()
-
给我们
print(df.head()),因为我只是猜到了 -
@anky print(df.head()) 与我最初发布的内容相同
标签: python pandas dataframe dictionary nested