If you only want the mean of the weight column, select the column (which is a Series) and call .mean():

In [479]: df
Out[479]: 
         ID  birthyear    weight
0    619040       1962  0.123123
1    600161       1963  0.981742
2  25602033       1963  1.312312
3    624870       1987  0.942120

In [480]: df.loc[:, 'weight'].mean()
Out[480]: 0.83982437500000007
Answer from DSM on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.mean.html
pandas.DataFrame.mean — pandas 3.0.6 documentation
Return the mean of the values over the requested axis. ... Axis for the function to be applied on. For Series this parameter is unused and defaults to 0. For DataFrames, specifying axis=None will apply the aggregation across both axes. Added in version 2.0.0. ... Exclude NA/null values when computing the result. ... Include only float, int, boolean columns...
Discussions

Finding mean of column in a pandas dataframe where the values in column may be string.
I think a way to go about this is : import numpy as np pd['BasePay'] = pd['BasePay'].replace("Not provided", np.nan).astype(float) # You can't use int because nan's are of type float. Now pd['BasePay'].mean() doesn't throw any error anymore, it'll compute the mean without taking the "Nan" (not a number) into account. Note that it does so quietly, you're not seeing any message telling you that the nan's weren't taken into account so don't forget about it because in some cases this might not be the behavior you're expecting. pd.to_numeric(df['BasePay']).mean() Does exactly the same but doesn't change the initial column as I did above and it also behaves quietly, you won't get any message telling you that the strings "Not provided" were replaced by Nan's. In any case, be aware of the types of your columns and always check the expected behavior of your operations. More on reddit.com
🌐 r/learnpython
4
1
June 19, 2019
In a pandas dataframe, how to find the average value within specific categories as denoted in another column. See example in the description.
GroupBy in Pandas More on reddit.com
🌐 r/learnpython
3
1
May 27, 2023
What’s your favorite way to add a “total” row at the bottom of a dataFrame?
You don't. Data frames are not meant to have a totals row, as it's against the tidy data principles. You add totals in your display step, so in your preferred table package. More on reddit.com
🌐 r/rstats
24
15
May 3, 2024
Pandas - create new column with average of other columns in CSV
import pandas df = pandas.read_csv("table.csv") print(df) avg = df.groupby("MeetingId")["PrizeMoney"].mean() avg.name = "AvgPrizeMoney" df = df.merge(avg, on="MeetingId") print(df) More on reddit.com
🌐 r/learnpython
3
9
November 24, 2022
🌐
Saturn Cloud
saturncloud.io › blog › what-is-pandas-mean-for-a-certain-column
What is Pandas Mean for a Certain Column | Saturn Cloud Blog
May 1, 2026 - The syntax for the mean() function in Pandas is as follows: ... Here, df is the DataFrame, and column_name is the name of the column for which we want to calculate the mean.
🌐
Pandas
pandas.pydata.org › docs › dev › getting_started › intro_tutorials › 06_calculate_statistics.html
How to calculate summary statistics — pandas 3.1.0.dev0 documentation
If we are only interested in the average age for each gender, the selection of columns (square brackets [] as usual) is supported on the grouped data as well: In [10]: titanic.groupby("Sex")["Age"].mean() Out[10]: Sex female 27.915709 male 30.726645 Name: Age, dtype: float64 ... The Pclass column contains numerical data but actually represents 3 categories (or factors) with respectively the labels ‘1’, ‘2’ and ‘3’. Calculating statistics on these does not make much sense. Therefore, pandas provides a Categorical data type to handle this type of data.
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › python-pandas-dataframe-mean
Pandas DataFrame mean() Method - GeeksforGeeks
July 11, 2025 - If the method is applied on a Pandas Dataframe object, then the method returns a Pandas series object which contains the mean of the values over the specified axis. Syntax: DataFrame.mean(axis=0, skipna=True, level=None, numeric_only=False, ...
Find elsewhere
🌐
W3Schools
w3schools.com › python › pandas › ref_df_mean.asp
Pandas DataFrame mean() Method
Return the average (mean) value ... pd.DataFrame(data) print(df.mean()) Try it Yourself » · The mean() method returns a Series with the mean value of each column....
🌐
Reddit
reddit.com › r/learnpython › finding mean of column in a pandas dataframe where the values in column may be string.
r/learnpython on Reddit: Finding mean of column in a pandas dataframe where the values in column may be string.
June 19, 2019 -

So , I recently started learning pandas in python and I had an exercise wherein I have to find the average of values in a particular column in a dataframe. Suppose the name of my column is "BasePay", the required command would be:-

dataframe['BasePay'].mean().

However it gives me these errors:-

Traceback (most recent call last)

~/anaconda3/lib/python3.7/site-packages/pandas/core/nanops.py in f(values, axis, skipna, **kwds).

TypeError: unsupported operand type(s) for +: 'float' and 'str'.

Also worth noting that for some values , the "BasePay " column also contains string "Not provided" in place of a numeric value .

So my question is, what adjustments do I need to make in my command to calculate the average of only the numeric values and ignore the strings in the column to find the average of all values in that column?

🌐
IONOS
ionos.com › digital guide › websites › web development › python pandas: dataframe mean
How to calculate averages with pandas mean()
June 26, 2025 - The code above cal­cu­lates the mean for each column (A, B and C) by finding the sum of the elements in the re­spec­tive column and then dividing it by the number of elements in the column. The result is the following pandas Series:
🌐
pandas
pandas.pydata.org › pandas-docs › dev › reference › api › pandas.DataFrame.mean.html
pandas.DataFrame.mean — pandas 3.1.0.dev0 documentation
This computes the arithmetic mean of the values in each column (or row when axis=1), skipping missing values by default.
🌐
Programiz
programiz.com › python-programming › pandas › methods › mean
Pandas mean() (With Examples)
The mean() method in Pandas is used to compute the arithmetic mean of a set of numbers. import pandas as pd # sample DataFrame data = { 'Math': [85, 90, 78], 'Physics': [92, 88, 84] } df = pd.DataFrame(data) # compute the mean for each subject (column) mean_scores = df.mean() print(mean_scores) ...
🌐
Vultr Docs
docs.vultr.com › python › third party › pandas › dataframe › mean()
Python Pandas DataFrame mean() - Calculate Column Mean
December 24, 2024 - Applying mean() computes the average across each numeric column, resulting in a Series where each index corresponds to a column name from the DataFrame. Understand that the mean() function can compute along different axes.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › how to get column average or mean in pandas dataframe
How to Get Column Average or Mean in Pandas DataFrame - Spark By {Examples}
December 12, 2024 - To get column average or mean from pandas DataFrame use either mean() or describe() method. The mean() method is used to return the mean of the values
🌐
Erikrood
erikrood.com › Python_References › pandas_column_average_median_final.html
Get the mean and median from a Pandas column in Python
Looking to land a data science role? Practice interviewing with a few questions per week · Get the mean and median from a Pandas column in Python · import modules · import pandas as pd import numpy as np · create dummy dataframe · raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar ...
🌐
Saturn Cloud
saturncloud.io › blog › calculating-averages-of-multiple-columns-ignoring-nan-a-guide-for-data-scientists
Calculating Averages of Multiple Columns Ignoring NaN A Guide for Data Scientists | Saturn Cloud Blog
May 1, 2026 - To calculate averages of multiple columns in pandas, we can use the mean() function. However, if the dataset contains NaN values, the mean() function will return NaN for any column that contains at least one NaN value.
🌐
Statology
statology.org › home › how to calculate the mean of columns in pandas
How to Calculate the Mean of Columns in Pandas
October 5, 2021 - #find mean of all numeric columns in DataFrame df.mean() points 18.2 assists 6.8 rebounds 8.0 dtype: float64 · Note that the mean() function will simply skip over the columns that are not numeric. How to Calculate the Median in Pandas How to Calculate the Sum of Columns in Pandas How to Find the Max Value of Columns in Pandas
🌐
stataiml
stataiml.com › posts › calculate_mean_sel_columns_python
Calculate Mean of Rows on Selected Columns in pandas DataFrame - stataiml
April 5, 2024 - In pandas DataFrame, you can use the mean() function as shown below to calculate the mean of row values for selected columns.
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to calculate the mean of column values in a pandas dataframe
5 Best Ways to Calculate the Mean of Column Values in a Pandas DataFrame - Be on the Right Side of Change
March 5, 2024 - This code uses the describe() function to get various summary statistics of the ‘sales’ column and then specifically extracts the mean. It is more verbose but insightful when needing a broader statistical context. The aggregate() function, also known as agg(), allows multiple aggregation operations to be performed at once. It’s versatile for complex data aggregation tasks, including calculating the mean. ... import pandas as pd # Sample dataframe df = pd.DataFrame({'sales': [3, 4, 5, 2, 6]}) # Calculate the mean using aggregate function mean_sales = df.aggregate({'sales': 'mean'}) print(mean_sales)
🌐
Statology
statology.org › home › how to calculate the mean by group in pandas (with examples)
How to Calculate the Mean by Group in Pandas (With Examples)
August 29, 2022 - The following code shows how to calculate the mean value of the points column and the mean value of the assists column, grouped by the team column: