2 回答
TA贡献1801条经验 获得超15个赞
想法是从列中删除重复项error
,添加DataFrame.reindex
添加可能删除的列并分配回来:
cols = df.filter(like='error').columns
df[cols] = (df[cols].apply(lambda x: pd.Series(x.unique()), axis=1)
.reindex(np.arange(len(cols)), axis=1))
print (df)
Feature name error1 error2 error3 error4
0 1 A overlaps NaN NaN NaN
1 2 B No error NaN NaN
2 3 C overlaps invalid NaN NaN
3 4 D invalid overlaps NaN NaN
TA贡献1860条经验 获得超8个赞
尝试用
out = pd.DataFrame(list(map(pd.unique, df.loc[:,'error1':].values)),index=df.Feature)
Out[333]:
0 1 2
Feature
1 overlaps None None
2 No error None
3 overlaps invalid None
4 invalid overlaps None
添加回答
举报