我有一个字符串的数据帧。当前数据帧如下所示: 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()
,也试过使用apply
like this。但我认为,由于其他dict都缺少'TakeOverDecision'
键,apply无法处理它
你试过
from_dict
函数吗也许这能帮上忙
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.from_dict.html
相关问题 更多 >
编程相关推荐