0

I have a multi index dataframe (with Order and Order 2 as index) that looks like:

Order  Order2   Units Cost Units2 
1       1       100   2.1  120
        2       200   2.2  320
        3       100   2.4  520
2       1       100   3.1  120
        2       333   2.2  520
        3       333   2.3  620
        4       100   2.4  220

.... ...

I would like to apply the mean function (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.mean.html) df.mean for the Units column for each Order value

So the data should come out as :

Order  Order2   Units Cost Units2 Units_Mean
1       1       100   2.1  120     133.33
        2       200   2.2  320     
        3       100   2.4  520
2       1       100   3.1  120     216.5
        2       333   2.2  520
        3       333   2.3  620
        4       100   2.4  220

.... ...

Could you advise what would be the most efficent way (from computational perspective) as the df I have is in billions.

asimo
  • 2,340
  • 11
  • 29

0 Answers0