Python 3.x 数据帧分解并映射正确的数据
我有一个这样的数据帧Python 3.x 数据帧分解并映射正确的数据,python-3.x,pandas,Python 3.x,Pandas,我有一个这样的数据帧 Bad ActionID ActionText Status [3,2,1] [2,16,16] ['a','','c'] yes [1,2] [1,10] ['yes','no'] nil 我希望输出数据帧被分解并映射到行中元素的正确位置。因此,输出将类似于 Bad ActionID ActionText Status 3 2 'a' "yes" 2 16
Bad ActionID ActionText Status
[3,2,1] [2,16,16] ['a','','c'] yes
[1,2] [1,10] ['yes','no'] nil
我希望输出数据帧被分解并映射到行中元素的正确位置。因此,输出将类似于
Bad ActionID ActionText Status
3 2 'a' "yes"
2 16 '' "yes"
1 16 'c' "yes"
1 1 'yes' "nil"
2 10 'no' "nil"
请帮忙
为了更清楚,我删除了日期栏。原始数据的使用:
#if necessary convert string repr to lists
#import ast
#df.iloc[:, :-1] = df.iloc[:, :-1].applymap(ast.literal_eval)
df = pd.concat([df[x].explode() for x in df], axis=1).reset_index(drop=True)
print (df)
Bad ActionID ActionText Status
0 3 2 a yes
1 2 16 yes
2 1 16 c yes
3 1 1 yes nil
4 2 10 no nil
无法从重复的轴重新编制索引我得到了这个error@R.singh-每行始终有匹配的列表长度?是的,每个列元素的长度,如日期、actionId、,操作文本将始终与错误列长度相同。Hi@jezrael日期后可能会有另一列“状态”,该列仅为字符串,可以为common@R.singh-是的,不幸的是数据相关问题。