小编Mat*_*t M的帖子

Pandas - 字典列表的列扩展 - 如何优化?

我有一个test包含 3 列id, name, value的数据框以下列test['values']test外观示例如下:

    name                  values
0   impressions           [{'value': 17686, 'end_time': '2018-06-12T07:0...
1   reach                 [{'value': 6294, 'end_time': '2018-06-12T07:00...
2   follower_count        [{'value': 130, 'end_time': '2018-06-12T07:00:...
3   email_contacts        [{'value': 1, 'end_time': '2018-06-12T07:00:00...
4   phone_call_clicks     [{'value': 0, 'end_time': '2018-06-12T07:00:00...
5   text_message_clicks   [{'value': 0, 'end_time': '2018-06-12T07:00:00...
6   get_directions_clicks [{'value': 0, 'end_time': '2018-06
Run Code Online (Sandbox Code Playgroud)

测试值单元格看起来像这样:

[{'end_time': '2018-06-12T07:00:00+0000', 'value': 17686},
 {'end_time': '2018-06-13T07:00:00+0000', 'value': 4064}]
Run Code Online (Sandbox Code Playgroud)

我可以通过执行以下操作来扩展它:

test[['Values 1', 'Values 2']] = test['values'].apply(pd.Series)
test[['Date 1', 'Values 1']] = test['Values 1'].apply(pd.Series) …
Run Code Online (Sandbox Code Playgroud)

python pandas pandas-groupby

3
推荐指数
1
解决办法
1097
查看次数

标签 统计

pandas ×1

pandas-groupby ×1

python ×1