Use GroupBy.sum:

df.groupby(['Fruit','Name']).sum()

Out[31]: 
               Number
Fruit   Name         
Apples  Bob        16
        Mike        9
        Steve      10
Grapes  Bob        35
        Tom        87
        Tony       15
Oranges Bob        67
        Mike       57
        Tom        15
        Tony        1

To specify the column to sum, use this: df.groupby(['Name', 'Fruit'])['Number'].sum()

Answer from Steven G on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.groupby.html
pandas.DataFrame.groupby — pandas 3.0.6 documentation
Used to determine the groups for the groupby. If by is a function, it’s called on each value of the object’s index. If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups (the Series’ values are first aligned; see .align() method).
Discussions

python - How to use df.groupby() to select and sum specific columns w/o pandas trimming total number of columns - Data Science Stack Exchange
I got Column1, Column2, Column3, Column4, Column5, Column6 I'd like to group Column1 and get the row sum of Column3,4 and 5 When I apply groupby() and get this that is correct but it's leaving out More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
July 10, 2020
How can I group and sum certain columns of a pandas dataframe
Yes. Bin the column names using pd.cut , which returns an object containing the bin label where each column name falls into. Use those labels to group your columns (axis=1 ) using groupby, and aggregate the results with sum. I'm assuming that your column names are floats and not strings. More on reddit.com
🌐 r/learnpython
7
2
May 25, 2021
Pandas groupby.sum() or grouby.agg(sum) to retain variable as index?
I have a somewhat larger data set. I want to create a summary for a specific column, with the totals of two other column. So Column A contains a… More on reddit.com
🌐 r/learnpython
1
3
November 10, 2021
Pandas group by column find percentage of count in each group
Surely you want to sum the total, not the survival indicator? train_df.groupby('Sex')['Total'].transform('sum') Then it's straightforward scalar arithmetic. More on reddit.com
🌐 r/learnpython
1
1
December 7, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › pandas-groupby-and-sum
Pandas Groupby and Sum - GeeksforGeeks
July 23, 2025 - Example 1: Pandas groupby() & sum() by Column Name · In this example, we group data on the Points column and calculate the sum for all numeric columns of DataFrame. Python3 · # use groupby() to compute sum df.groupby(['Points']).sum() Output: Example 2: Pandas groupby() & sum() on Multiple Columns ·
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas groupby() and sum() with examples
Pandas groupby() and sum() With Examples
July 3, 2025 - Use DataFrame.groupby().sum() function to group rows based on one or multiple columns and calculate the sum of these grouped data. groupby() function
🌐
Pandas
pandas.pydata.org › docs › user_guide › groupby.html
Group by: split-apply-combine — pandas 3.0.6 documentation
SELECT Column1, Column2, mean(Column3), sum(Column4) FROM SomeTable GROUP BY Column1, Column2 · We aim to make operations like this natural and easy to express using pandas.
🌐
Data36
data36.com › home › pandas groupby(), count(), sum() and other aggregation methods (pandas tutorial 2.)
Pandas groupby(), count(), sum() and other aggregation methods (tutorial)
June 26, 2022 - Then on this subset, we applied a groupby pandas method… Oh, did I mention that you can group by multiple columns? Now you know that, too! 😉 (Syntax-wise, watch out for one thing: you have to put the name of the columns into a list.
Find elsewhere
🌐
Codecademy
codecademy.com › docs › python:pandas › groupby › .sum()
Python:Pandas | GroupBy | .sum() | Codecademy
April 20, 2023 - The .sum() method produces a new Series or DataFrame with aggregate sums for the groups in a GroupBy object.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › search.html
Search - pandas 3.0.6 documentation
Created using Sphinx 9.0.4 · Built with the PyData Sphinx Theme 0.16.1
🌐
InfluxData
influxdata.com › home › pandas groupby function: a brief overview of all it can do
Pandas Groupby Function: A Brief Overview of All It Can Do | InfluxData
January 3, 2024 - These issues can be raised on a higher level and allow you to uncover anomalies. There’s another very useful function you can use in pandas. Groupby apply allows you to apply a custom function to each group in your data.
🌐
Facebook
facebook.com › groups › statisticsglobepython › posts › 736489724995518
How to calculate sum by group in pandas
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.groupby.GroupBy.sum.html
pyspark.pandas.groupby.GroupBy.sum — PySpark 4.2.0 documentation
Skip to main content · GitHub · pyspark.pandas.groupby.GroupBy.sum# · GroupBy.sum(numeric_only=False, min_count=0)[source]# · Compute sum of group values · New in version 3.3.0 · Parameters · numeric_onlybool, default False · Include only float, int, boolean columns · New in version 3.4.0
🌐
Reddit
reddit.com › r/learnpython › pandas groupby.sum() or grouby.agg(sum) to retain variable as index?
r/learnpython on Reddit: Pandas groupby.sum() or grouby.agg(sum) to retain variable as index?
November 10, 2021 - I have a somewhat larger data set. I want to create a summary for a specific column, with the totals of two other column. So Column A contains a…
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 2.2 › reference › api › pandas.core.groupby.DataFrameGroupBy.sum.html
pandas.core.groupby.DataFrameGroupBy.sum — pandas 2.2.3 documentation
>>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]] >>> df = pd.DataFrame(data, columns=["a", "b", "c"], ... index=["tiger", "leopard", "cheetah", "lion"]) >>> df a b c tiger 1 8 2 leopard 1 2 5 cheetah 2 5 8 lion 2 6 9 >>> df.groupby("a").sum() b c a 1 10 7 2 11 17
🌐
scikit-learn
scikit-learn.org › stable › modules › generated › sklearn.metrics.confusion_matrix.html
confusion_matrix — scikit-learn 1.9.1 documentation
By definition a confusion matrix \(C\) is such that \(C_{i, j}\) is equal to the number of observations known to be in group \(i\) and predicted to be in group \(j\).
🌐
Shane Lynn
shanelynn.ie › home › use pandas groupby to group and summarise dataframes
Group and Aggregate your Data Better using Pandas Groupby
October 16, 2021 - In older Pandas releases (< 0.20.1), renaming the newly calculated columns was possible through nested dictionaries, or by passing a list of functions for a column. Our final example calculates multiple values from the duration column and names the results appropriately. Note that the results have multi-indexed column headers. Note this syntax will no longer work for new installations of Python Pandas. # Define the aggregation calculations aggregations = { # work on the "duration" column 'duration': { # get the sum, and call this result 'total_duration' 'total_duration': 'sum', # get mean, cal
🌐
Medium
medium.com › @fintechashish › data-science-using-python-groupby-categories-in-a-column-for-the-sum-of-values-in-other-columns-96574489825
Data Science using Python : groupby categories in a column for the sum of values in other columns in a pandas dataframe(with conditions) | by Ashish Sharma | Medium
May 12, 2020 - Step : 4 — To analyse the total sales done by each employee, we need to use add all the columns on axis=1 of the data frame sales1. ... For those who doesn’t want to create a new dataframe they can simply use the code sales.groupby([‘Employee’])[‘Spring’,’Winter’,’Autumn’, ‘Summer’].sum().sum(axis=1) and they will get the same result.
🌐
W3Schools
w3schools.com › sql › sql_aggregate_functions.asp
SQL Aggregate Functions
An aggregate function is a function that performs a calculation on a set of values, and returns a single value.