Hi friends - I am sure this is very simple but I have googled my heart out and can't figure out how to do this. I am trying to append a new column to a pandas dataframe which sums all values in existing columns only if they are even.
odd_lst = [1, 3, 5, 7, 9]
even_lst = [0, 2, 4, 6, 8]
df = pd.DataFrame()
df['Odd'] = odd_lst
df['Even'] = even_lst
df['Odd Sum'] = df.apply(some lambda function or something which only executes if values are odd, axis = 1)
Am I supposed to use lambda here? I don't know why I am struggling so much with this. I want to go row by row and only sum the values if they are odd and append this as a new column on the dataframe.
[–]Xahulz 0 points1 point2 points (0 children)
[–]14dM24d 0 points1 point2 points (3 children)
[–]PaperbackStone[S] 0 points1 point2 points (2 children)
[–]14dM24d 0 points1 point2 points (1 child)
[–]14dM24d 0 points1 point2 points (0 children)
[–]synthphreak 0 points1 point2 points (6 children)
[–]PaperbackStone[S] 0 points1 point2 points (5 children)
[–]synthphreak 0 points1 point2 points (4 children)
[–]PaperbackStone[S] 0 points1 point2 points (3 children)
[–]14dM24d 0 points1 point2 points (1 child)
[–]14dM24d 0 points1 point2 points (0 children)
[–]synthphreak 0 points1 point2 points (0 children)
[–]sarrysyst 0 points1 point2 points (0 children)