Reputation: 23
i am a newbie in python and need your support. I have a below output from test data frame
LS last height weight
0 88+2 Doe 5.5 130
1 90+2 Bo 6.0 150
output[]
0 [88, 2]
1 [90, 2]
I'm trying to sum the values in the 'LS' column. is the output for LS columns should be sum ie 90 & 92. I split them into a list and trying to sum them
Can you please suggest how to proceed?
Upvotes: 1
Views: 45
Reputation: 323396
We can try eval
df.LS=pd.eval(df.LS)
#pd.eval(df.LS)
#Out[394]: [90, 92]
Upvotes: 2
Reputation: 7614
Try this:
df = pd.DataFrame({
'LS': [[88, 2], [90,2]]
})
df['sum'] = df['LS'].apply(sum)
print(df)
LS sum
0 [88, 2] 90
1 [90, 2] 92
Upvotes: 1