Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas Mean for Certain Column

I have a pandas dataframe like that:

enter image description here

How can I able to calculate mean (min/max, median) for specific column if Cluster==1 or CLuster==2?

Thanks!

like image 767
Keithx Avatar asked Dec 24 '22 02:12

Keithx


1 Answers

You can create new df with only the relevant rows, using:

newdf = df[df['cluster'].isin([1,2)]

newdf.mean(axis=1)

In order to calc mean of a specfic column you can:

newdf["page"].mean(axis=1) 
like image 89
Yaron Avatar answered Jan 08 '23 23:01

Yaron