mam serię pandy SF:python, najlepszym sposobem konwersji serię pandy w dataframe pandy
email
[email protected] [1.0, 0.0, 0.0]
[email protected] [2.0, 0.0, 0.0]
[email protected] [1.0, 0.0, 0.0]
[email protected] [4.0, 0.0, 0.0]
[email protected] [1.0, 0.0, 3.0]
[email protected] [1.0, 5.0, 0.0]
I chciałbym, aby przekształcić go w następujący DataFrame:
index | email | list
_____________________________________________
0 | [email protected] | [1.0, 0.0, 0.0]
1 | [email protected] | [2.0, 0.0, 0.0]
2 | [email protected] | [1.0, 0.0, 0.0]
3 | [email protected] | [4.0, 0.0, 0.0]
4 | [email protected] | [1.0, 0.0, 3.0]
5 | [email protected] | [1.0, 5.0, 0.0]
I znalazłem sposób, aby to zrobić, ale wątpię, że jest to bardziej wydajny:
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)
Co powiesz na 'pd.DataFrame ({'email': sf.index, 'list': sf.values})'? – EdChum
to działa, dzięki @EdChum – woshitom
Czy mam opublikować jako odpowiedź? – EdChum