将Dict.的数据帧拆分为具有键和值的新数据帧

2024-09-30 02:21:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个字符串的数据帧。当前数据帧如下所示: Current dataframe

每个数据点包含一个字典,如下所示:

"{'Index': 1, 'TimeSpent': 74088, 'RealInc': 'Obstacle_bef', 'IdentifiedIncident': 'Obstacle', 'TrLev': 7, 'TakeOverDecision': 'stay_put'},{'Index': 2, 'TimeSpent': 11336, 'RealInc': 'Obstacle_after_success', 'IdentifiedIncident': 'Pedestrian', 'TrLev': 7 },{'Index': 3, 'TimeSpent': 38594, 'RealInc': 'Cyclist_before', 'IdentifiedIncident': 'Cyclist', 'TrLev': 7, 'TakeOverDecision': 'stay_put'},{'Index': 4, 'TimeSpent': 16011, 'RealInc': 'Cyclist_after_success', 'IdentifiedIncident': 'Pedestrian', 'TrLev': 7 }".

我想创建一个新的数据帧,其中每一列表示字典的键。我试过使用eval(),也试过使用applylike this。但我认为,由于其他dict都缺少'TakeOverDecision'键,apply无法处理它

太好了! Desired dataframe


Tags: 数据dataframeindex字典putsuccessafterstay

热门问题