How to do an R style aggregate in Python Pandas?
up vote 0 down vote favorite I need to do an aggregate (at least that what you would call it in R) over the mtcars data set that I have uploaded into python. The end goal is to get the average mpg for each value of cyl in the data set (There are three values for cyl, 4,6,8). Here is the R code for what I want to do mean_each_gear <- aggregate(mtcars$mpg ~ mtcars$cyl, FUN = mean) output: cyl mpg 1 4 26.66364 2 6 19.74286 3 8 15.10000 The closest I've come with in Pandas is this mtcars.agg(['mean']) I'm not sure how I would do that in Pandas. Any help would be appreciated! python r pandas aggregate share | improve this question edited Nov 9 at 23:08 asked Nov 9 at 22:59 Tanner 10 4 add a comment | up vote 0 down vote favorite I need to do an aggregate (at least that what you would call it in R) over the mtcars data set that I have uploaded into python. The end goal is to get the average mpg f...