MYYA
使用来自伦敦家庭 SmartMeter 能源消耗数据的低碳伦敦数据问题是LCLid不会1从MAC000228到均匀递增MAC000295。print(data.LCLid.unique())array(['MAC000228', 'MAC000229', 'MAC000230', 'MAC000231', 'MAC000232', 'MAC000233', 'MAC000234', 'MAC000235', 'MAC000237', 'MAC000238', 'MAC000239', 'MAC000240', 'MAC000241', 'MAC000242', 'MAC000243', 'MAC000244', 'MAC000245', 'MAC000246', 'MAC000248', 'MAC000249', 'MAC000250', 'MAC000251', 'MAC000252', 'MAC000253', 'MAC000254', 'MAC000255', 'MAC000256', 'MAC000258', 'MAC000260', 'MAC000262', 'MAC000263', 'MAC000264', 'MAC000267', 'MAC000268', 'MAC000269', 'MAC000270', 'MAC000271', 'MAC000272', 'MAC000273', 'MAC000274', 'MAC000275', 'MAC000276', 'MAC000277', 'MAC000279', 'MAC000280', 'MAC000281', 'MAC000282', 'MAC000283', 'MAC000284', 'MAC000285', 'MAC000287', 'MAC000289', 'MAC000291', 'MAC000294', 'MAC000295'], dtype=object)print(len(data.LCLid.unique()))>>> 55解决问题import pandas as pdimport numpy as npdf = pd.read_csv('Power-Networks-LCL-June2015(withAcornGps)v2.csv')# determine the rows needed for the MAC000228 - MAC000295df[df.LCLid == 'MAC000228'].iloc[0, :] # first row of 228df[df.LCLid == 'MAC000295'].iloc[-1, :] # last row of 295# create a dataframe with the desired datadata = df[['LCLid', 'DateTime', 'KWH/hh (per half hour) ']].iloc[6989700:9032044, :].copy()# fix the datadata.DateTime = pd.to_datetime(data.DateTime)data.rename(columns={'KWH/hh (per half hour) ': 'KWH/hh'}, inplace=True)data['KWH/hh'] = data['KWH/hh'].str.replace('Null', 'NaN')data['KWH/hh'].fillna(np.nan, inplace=True)data['KWH/hh'] = data['KWH/hh'].astype('float')data.reset_index(drop=True, inplace=True)# aggregate your functionsagg_data = data.groupby('LCLid')['KWH/hh'].agg(['sum', 'min', 'max', 'mean']).reset_index()print(agg_data)agg_data LCLid sum min max mean0 MAC000228 5761.288000 0.021 1.616 0.1463561 MAC000229 6584.866999 0.008 3.294 0.1674562 MAC000230 8911.154000 0.029 2.750 0.2263843 MAC000231 3174.314000 0.000 1.437 0.0806634 MAC000232 2083.042000 0.005 0.736 0.0529465 MAC000233 2241.591000 0.000 3.137 0.0569936 MAC000234 9700.328001 0.029 2.793 0.2466467 MAC000235 8473.999003 0.011 3.632 0.2231948 MAC000237 22263.294998 0.036 4.450 0.5982999 MAC000238 7814.889998 0.016 2.835 0.19878110 MAC000239 6113.029000 0.015 1.346 0.15548111 MAC000240 7280.662000 0.000 3.146 0.22239912 MAC000241 4181.169999 0.024 1.733 0.19496313 MAC000242 1654.336000 0.000 1.481 0.04208814 MAC000243 11057.366999 0.009 3.588 0.28198915 MAC000244 5894.271000 0.005 1.884 0.14993916 MAC000245 22788.699005 0.037 4.743 0.58008717 MAC000246 13787.060005 0.014 3.516 0.35107518 MAC000248 10192.239001 0.000 4.351 0.25953619 MAC000249 24401.468995 0.148 5.242 0.89304220 MAC000250 5850.003000 0.000 2.185 0.14899921 MAC000251 8400.234000 0.035 3.505 0.21393122 MAC000252 21748.489004 0.135 4.171 0.55497823 MAC000253 9739.408999 0.009 1.714 0.24820124 MAC000254 9351.614001 0.009 2.484 0.23820925 MAC000255 14142.974002 0.097 3.305 0.36022026 MAC000256 20398.665001 0.049 3.019 0.52068027 MAC000258 6646.485998 0.017 2.319 0.16966628 MAC000260 5952.563001 0.006 2.192 0.15195229 MAC000262 13909.603999 0.000 2.878 0.35518130 MAC000263 3753.997000 0.015 1.060 0.09586331 MAC000264 7022.967000 0.020 0.910 0.17943232 MAC000267 8797.094000 0.029 2.198 0.22489833 MAC000268 3734.252001 0.000 1.599 0.09535934 MAC000269 2395.232000 0.000 1.029 0.06116735 MAC000270 15569.711002 0.131 2.249 0.39750136 MAC000271 7244.860000 0.028 1.794 0.18497437 MAC000272 8703.658998 0.034 3.295 0.22244638 MAC000273 3622.199002 0.005 5.832 0.09258739 MAC000274 28724.718997 0.032 3.927 0.73442240 MAC000275 5564.004999 0.012 1.840 0.16129041 MAC000276 11060.774001 0.000 1.709 0.31572442 MAC000277 8446.528999 0.027 1.938 0.24107543 MAC000279 3444.160999 0.016 1.846 0.09835444 MAC000280 12595.780001 0.125 1.988 0.36043645 MAC000281 6282.568000 0.024 1.433 0.17953846 MAC000282 4457.989001 0.030 1.830 0.12744447 MAC000283 5024.917000 0.011 2.671 0.14362748 MAC000284 1293.503000 0.000 0.752 0.04797549 MAC000285 2399.018000 0.006 0.931 0.06856750 MAC000287 1407.290000 0.000 2.372 0.04525351 MAC000289 4767.490999 0.000 2.287 0.13643652 MAC000291 13456.678999 0.072 3.354 0.38506053 MAC000294 9477.966000 0.053 2.438 0.27126454 MAC000295 7750.128000 0.010 1.839 0.221774