我有一个熊猫系列科幻小说:
email
email1@email.com [1.0, 0.0, 0.0]
email2@email.com [2.0, 0.0, 0.0]
email3@email.com [1.0, 0.0, 0.0]
email4@email.com [4.0, 0.0, 0.0]
email5@email.com [1.0, 0.0, 3.0]
email6@email.com [1.0, 5.0, 0.0]
我想将其转换为以下DataFrame:
index | email | list
_____________________________________________
0 | email1@email.com | [1.0, 0.0, 0.0]
1 | email2@email.com | [2.0, 0.0, 0.0]
2 | email3@email.com | [1.0, 0.0, 0.0]
3 | email4@email.com | [4.0, 0.0, 0.0]
4 | email5@email.com | [1.0, 0.0, 3.0]
5 | email6@email.com | [1.0, 5.0, 0.0]
我找到了一种方法,但是我怀疑这是更有效的方法:
df1 = pd.DataFrame(data=sf.index, columns=['email'])
df2 = pd.DataFrame(data=sf.values, columns=['list'])
df = pd.merge(df1, df2, left_index=True, right_index=True)
reset_index
调用来实现。