我有以下数据框:
CustID Condition Month Reading Consumption
0 108000601 True June 20110606 28320.0
1 108007000 True July 20110705 13760.0
2 108007000 True August 20110804 16240.0
3 108008000 True September 20110901 12560.0
4 108008000 True October 20111004 12400.0
5 108000601 False November 20111101 9440.0
6 108090000 False December 20111205 12160.0
7 108000601 True January 20120106 11360.0
8 108000601 True February 20120206 10480.0
9 108000601 True March 20120306 9840.0
10 108000601 True April 20120410 12560.0
11 108000601 True May 20120507 9120.0
12 108008902 True June 20120606 11520.0
13 108034877 True July 20120707 14160.0
14 108000601 True August 20120804 14000.0
15 108007000 True September 20120906 14880.0
我试图使用这个groupby计算每个条件的平均消耗量,
monthStats = dfm.groupby(['Month','Condition']).Consumption.mean()
但是没有得到正确的意思。它似乎只给我消费一个CustID,而不是每个条件每月消费。
输出提供的格式正是我正在寻找的,但消费结果看起来不正确。我在尝试计算平均消费时缺少什么?
这是当前小组输出的格式。
Month Condition Consumption
April True 13795.511299
False 160.811111
August True 11873.566197
False 30.593478