pandas get column average/mean

PepperoniPizza

I can't get the average or mean of a column in pandas. A have a dataframe. Neither of things I tried below gives me the average of the column weight

>>> allDF 
         ID           birthyear  weight
0        619040       1962       0.1231231
1        600161       1963       0.981742
2      25602033       1963       1.3123124     
3        624870       1987       0.94212

The following returns several values, not one:

allDF[['weight']].mean(axis=1)

So does this:

allDF.groupby('weight').mean()
DSM

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["weight"].mean()
Out[480]: 0.83982437500000007

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Get total of Pandas column

From Dev

Get total of Pandas column

From Java

Pandas get column values based on duplicate rows

From Java

Pandas - Get first row value of a given column

From Dev

How to get Pandas column multiindex names as a list

From Java

Get list from pandas DataFrame column headers

From Java

get list from pandas dataframe column

From Dev

Get list from pandas dataframe column or row?

From Dev

How to get particular Column of DataFrame in pandas?

From Java

Pandas dataframe get value of last nonzero column

From Dev

Unable to get min value of DataFrame column with Pandas

From Dev

get_dummies for Pandas column containing list

From Dev

How to get every nth column in pandas?

From Dev

Get indexes of unique values in column (pandas)

From Dev

Pandas DataFrame get column combined max values

From Dev

Group by column and get mean of the the group pandas

From Dev

Pandas DataFrame get substrings from column

From Dev

Pandas, Get count of a single value in a Column of a Dataframe

From Dev

Pandas get column contains character in all rows

From Dev

Pandas get the most frequent values of a column

From Dev

how to get numeric column names in pandas dataframe

From Dev

Pandas get the most frequent values of a column

From Dev

Pandas dataframe get value of last nonzero column

From Dev

How to get unique lists in a Pandas column of lists

From Dev

Get names based on another column in pandas dataframe

From Dev

Pandas - get_loc nearest for whole column

From Dev

Pandas DataFrame get column combined max values

From Dev

Pandas get DataFrame with unique column combinations

From Dev

Get number of maximum values per column in pandas

Related Related

HotTag

Archive