Search code examples
pythonpandasgroup-bymatchaverage

average of one wrt another or averageifs in python


enter image description here

I have a pandas df as displayed I would like to calculate Avg Rate by DC by Brand column which is a similar to averageif in excel , I have tried methods like groupby mean() but that does not give correct results


Solution

  • Your question is not clear but you may be looking for:

    df.groupby(['DC','Brand'])['Rate'].mean()