I have the following DataFrame:
In [1]:
import pandas as pd
df = pd.DataFrame({'a': [1,2,3], 'b': [2,3,4], 'c':['dd','ee','ff'], 'd':[5,9,1]})
df
Out [1]:
a b c d
0 1 2 dd 5
1 2 3 ee 9
2 3 4 ff 1
I would like to add a column 'e'
which is the sum of column 'a'
, 'b'
and 'd'
.
Going across forums, I thought something like this would work:
df['e'] = df[['a','b','d']].map(sum)
But it didn't.
I would like to know the appropriate operation with the list of columns ['a','b','d']
and df
as inputs.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…