python - How to use groupby method to combine rows or columns by using their mean? -


for example:

         b  c coffee  1  2  3 sprite  2  3  1 coffee  1  3  2 coke    2  4  5 sprite  2  3  1 coke    3  4  5 

if wanna use groupby method combine these rows (or columns) using mean, how can that?

         b  c coffee  x  x  x sprite  x  x  x coke    x  x  x 

x mean

as said, it's call groupby. use level=0 group again index:

df out[65]:           b  c coffee  1  2  3 sprite  2  3  1 coffee  1  3  2 coke    2  4  5 sprite  2  3  1 coke    3  4  5  df.groupby(level=0).mean() out[66]:               b    c coffee  1.0  2.5  2.5 coke    2.5  4.0  5.0 sprite  2.0  3.0  1.0 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -