You can first select by iloc and then sum:

df['Fruit Total']= df.iloc[:, -4:-1].sum(axis=1)
print (df)
   Apples  Bananas  Grapes  Kiwis  Fruit Total
0     2.0      3.0     NaN    1.0          5.0
1     1.0      3.0     7.0    NaN         11.0
2     NaN      NaN     2.0    3.0          2.0

For sum all columns use:

df['Fruit Total']= df.sum(axis=1)
Answer from jezrael on Stack Overflow
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas sum dataframe columns with examples
Pandas Sum DataFrame Columns With Examples - Spark By {Examples}
November 4, 2024 - To sum Pandas DataFrame columns (given selected multiple columns) using either sum(), iloc[], eval(), and loc[] functions. Among these Pandas
Discussions

python - Pandas - Sum of multiple specific columns - Data Science Stack Exchange
0 Turning multiple binary columns into categorical (with less columns) with Python Pandas More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
July 5, 2020
python - Pandas : Sum multiple columns and get results in multiple columns - Stack Overflow
I have a "sample.txt" like this. idx A B C D cat J 1 2 3 1 x K 4 5 6 2 x L 7 8 9 3 y M 1 2 3 4 y N 4 5 6 5 z O 7 8 9 6 z With this More on stackoverflow.com
🌐 stackoverflow.com
October 23, 2017
Pandas: sum up multiple columns into one column without last column
If I have a data frame similar to this oneApples Bananas Grapes Kiwis2 3 nan 11 3 7 nannan nan 2 3I would like to add a column like thisApples Bananas Grap... More on janbasktraining.com
🌐 janbasktraining.com
1
June 24, 2021
pandas - sum of values in column for each unique combination of values from two other columns
You can use the pivot_table method and pass margins=True to compute the rows and columns sums. Then drop the row containing the row sums res = ( df.pivot_table(index='name 2', columns='name 1', values='value', aggfunc='sum', fill_value=0, margins=True, margins_name='sum') .drop(index='sum') # drop row sums .rename_axis(index=None, columns=None) # remove both axis names (optional) ) >>> res A B C sum X 6 2 2 10 Y 1 3 2 6 Z 5 3 0 8 More on reddit.com
🌐 r/learnpython
9
5
March 22, 2022
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.sum.html
pandas.DataFrame.sum — pandas 3.0.6 documentation
The behavior of DataFrame.sum with axis=None is deprecated, in a future version this will reduce over both axes and return a scalar To retain the old behavior, pass axis=0 (or do not pass axis). Added in version 2.0.0. ... Exclude NA/null values when computing the result. ... Include only float, int, boolean columns...
🌐
Saturn Cloud
saturncloud.io › blog › how-to-sum-two-columns-in-a-pandas-dataframe
How to Sum Two Columns in a Pandas DataFrame | Saturn Cloud Blog
May 1, 2026 - We then add these two columns together using the + operator and assign the result to a new column sum. Another way to add two columns in a Pandas DataFrame is to use the sum() function.
🌐
Moonbooks
en.moonbooks.org › Articles › How-to-sum-multiple-columns-together-of-a-dataframe-with-pandas-in-python-
How to sum multiple columns together of a dataframe with pandas in python ?
import pandas as pd import numpy ... 0 45 5 82 99 90 6 23 35 90 7 84 48 16 8 64 70 28 9 83 50 2 · To sum all columns of a dtaframe, a solution is to use sum()...
🌐
Statology
statology.org › home › how to calculate the sum of columns in pandas
How to Calculate the Sum of Columns in Pandas
July 29, 2020 - For columns that are not numeric, the sum() function will simply not calculate the sum of those columns.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › pandas-groupby-and-sum
Pandas Groupby and Sum - GeeksforGeeks
July 23, 2025 - Pandas dataframe.sum() function returns the sum of the values for the requested axis. If the input is the index axis then it adds all the values in a column and repeats the same for all the columns and returns a series containing the sum of ...
🌐
datagy
datagy.io › home › pandas tutorials › data analysis in pandas › pandas sum: add dataframe columns and rows
Pandas Sum: Add Dataframe Columns and Rows • datagy
December 15, 2022 - We can see that the we’ve created a new column that stores the sum of two of our columns. A great thing about this operation is that its vectorized, meaning that its very fast and takes advantage of the power of Pandas. In the next section, you’ll learn how to add dataframe columns conditionally. There may be times when you want to add multiple columns in a dataframe, but not all of them.
🌐
Data Science Parichay
datascienceparichay.com › home › blog › pandas – get sum of one or more columns
Pandas - Get Sum of one or more Columns - Data Science Parichay
November 14, 2021 - To get the sum of multiple columns together, first, create a dataframe with the columns you want to calculate the sum for and then apply the pandas dataframe sum() function.
🌐
IncludeHelp
includehelp.com › python › sum-up-multiple-columns-into-one-column-without-last-column.aspx
Pandas: Sum up multiple columns into one column without last column
For this purpose, we will use pandas.DataFrame.iloc property for slicing so that we can select from the first column to the second last column. Then we will use sum() method to calculate the sum and finally we will store all these values in a new column of the dataframe.
🌐
GeeksforGeeks
geeksforgeeks.org › python-pandas-dataframe-sum
Pandas dataframe.sum() - GeeksforGeeks
March 18, 2025 - DataFrame.sum() function in Pandas allows users to compute the sum of values along a specified axis. It can be used to sum values along either the index (rows) or columns, while also providing flexibility in handling missing (NaN) values.
🌐
Arab Psychology
scales.arabpsychology.com › home › how do i calculate the sum of columns in pandas?
How Do I Calculate The Sum Of Columns In Pandas?
December 24, 2025 - Often, an analyst needs to calculate ... facilitates this by allowing us to select multiple columns using a list of column names (double square brackets) before applying the sum() method....
🌐
Vultr Docs
docs.vultr.com › python › third party › pandas › dataframe › sum()
Python Pandas DataFrame sum() - Sum Column Values
December 25, 2024 - This snippet demonstrates how to get the sum of all columns. The sum() function, when used without specifying a column, returns the sum for each column.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_sum.asp
Pandas DataFrame sum() Method
import pandas as pd data = [[10, 18, 11], [13, 15, 8], [9, 20, 3]] df = pd.DataFrame(data) print(df.sum()) Try it Yourself » · The sum() method adds all values in each column and returns the sum for each column.
🌐
DataScience Made Simple
datasciencemadesimple.com › home › sum of two or more columns of pandas dataframe in python
Sum of two or more columns of pandas dataframe in python - DataScience Made Simple
November 15, 2019 - Sum of all the score is computed using simple + operator and stored in the new column namely total_score as shown below · df1['total_score']=df1['Mathematics1_score'] + df1['Mathematics2_score']+ df1['Science_score'] print(df1) ... With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.
🌐
Reddit
reddit.com › r/learnpython › pandas - sum of values in column for each unique combination of values from two other columns
r/learnpython on Reddit: pandas - sum of values in column for each unique combination of values from two other columns
March 22, 2022 -

Hello,

I have a DataFrame with multiple columns, where two of them are strings, one is date and one is int:

name 1   name 2   value   date        [other columns...]
  A        X        1     01.03.2022
  A        Y        1     11.03.2022
  B        Y        2     22.02.2022
  A        Z        2     05.02.2022
  A        Z        3     10.02.2022
  B        X        2     12.03.2022
  C        Y        2     11.03.2022
  B        Z        3     21.01.2022
  B        Y        1     10.01.2022
  A        X        5     15.01.2022
  C        X        1     08.02.2022
  C        X        1     10.01.2022
[...]

And I need to get something like this, for each specified period (start and end parameters dynamically provided):

     A    B    C   sum
X    6    2    2    10
Y    1    3    2     6
Z    5    3    0     8

Rows should be filtered by start=<date<=end, and for each value in combination of "name 1" and "name 2" I need to get sum of "value" and also total sum for each "name 2". If combination does not exists in DataFrame sum should be filled with 0.

There will be approx. 20 unique values in "name 1", 50 unique values in "name 2", "value" will be in 1-5 range, and there should be more or less 900 rows.

I am new to pandas. Could you please point me in right direction? What will be correct way to approach the problem? What functions/methods should I use?

🌐
Statology
statology.org › home › how to perform a groupby sum in pandas (with examples)
How to Perform a GroupBy Sum in Pandas (With Examples)
September 15, 2021 - #group by team and position, sum points and rebounds df.groupby(['team', 'position'])['points', 'rebounds'].sum() points rebounds team position A C 9 6 F 14 10 G 42 19 B C 4 12 F 15 14 G 12 6 · Depending on how you’d like the results to appear, you may or may not choose to use the reset_index() function. The following tutorials explain how to perform other common grouping operations in pandas: