Sum columns of a rows in a DataFrame
Sum columns of a rows in a DataFrame
Ok, I'm stumped and have surfed all available pages, followed it all, and still ugh!
So here is my df. I want to add all the values in row 4 together and have a row total at end, then do it for 5, 6, 7... I use .concat() and .sum() and get key errors or too many arguments, tried .groupby, and even .add() (worth a try) as the columns are 'lists', nothing gives totals.
1day 2day 3day 4day 5day 6day 7day
4 2.979 2.979 2.979 2.979 2.979 2.979 2.979
5 9.543 9.543 9.543 9.543 9.543 9.543 9.543
6 5.222 5.222 5.222 5.222 5.222 5.222 5.222
7 0.319 0.319 0.319 0.319 0.319 0.319 0.319
10 -4.491 -4.491 -4.491 -4.491 -4.491 -4.491 -4.491
14 2.178 2.178 2.178 2.178 2.178 2.178 2.178
15 7.507 7.507 7.507 7.507 7.507 7.507 7.507
16 0.612 0.612 0.612 0.612 0.612 0.612 0.612
17 4.488 4.488 4.488 4.488 4.488 4.488 4.488
I had some luck with df.groupby(df.index)[['1day','2day'...'7day'].sum() but it just pushes them together, not adds them. (I am aware that all the values are equal)
In excel, sum(a1:g1) but in pandas, I'm just writing into a deeper hole, please help!
df.sum(axis=1)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
df.sum(axis=1)
?– user3483203
4 secs ago