I have had to do this several times and I'm always frustrated. I have a dataframe:
df = pd.DataFrame([[1, 2, 3, 4], [5, 6, 7, 8]], ['a', 'b'], ['A', 'B', 'C', 'D'])
print df
A B C D
a 1 2 3 4
b 5 6 7 8
I want to turn df
into:
pd.Series([[1, 2, 3, 4], [5, 6, 7, 8]], ['a', 'b'])
a [1, 2, 3, 4]
b [5, 6, 7, 8]
dtype: object
I've tried
df.apply(list, axis=1)
Which just gets me back the same df
What is a convenient/effective way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…