python - Break Existing Dataframe Apart Based on Multi Index -


i have existing dataframe sorted this:

in [3]: result_gb_daily_average out[3]:                 nrel      avert month day 1     1    14.718417  37.250000       2    40.381167  45.250000       3    42.512646  40.666667       4    12.166896  31.583333       5    14.583208  50.416667       6    34.238000  45.333333       7    45.581229  29.125000       8    60.548479  27.916667       9    48.061583  34.041667       10   20.606958  37.583333       11    5.418833  70.833333       12   51.261375  43.208333       13   21.796771  42.541667       14   27.118979  41.958333       15    8.230542  43.625000       16   14.233958  48.708333       17   28.345875  51.125000       18   43.896375  55.500000       19   95.800542  44.500000       20   53.763104  39.958333       21   26.171437  50.958333       22   20.372688  66.916667       23   20.594042  42.541667       24   16.889083  48.083333       25   16.416479  42.125000       26   28.459625  40.125000       27    1.055229  49.833333       28   36.798792  42.791667       29   27.260083  47.041667       30   23.584917  55.750000 ...              ...        ... 12    2    34.491604  55.916667       3    26.444333  53.458333       4    15.088333  45.000000       5    10.213500  32.083333       6    19.087688  17.000000       7    23.078292  17.375000       8    41.523667  29.458333       9    17.173854  37.833333       10   11.488687  52.541667       11   15.203479  30.000000       12    8.390917  37.666667       13   70.067062  23.458333       14   24.281729  25.583333       15   31.826104  33.458333       16    5.085271  42.916667       17    3.778229  46.916667       18   31.276958  57.625000       19    7.399458  46.916667       20   18.531958  39.291667       21   26.831937  35.958333       22   55.514000  32.375000       23   24.018875  34.041667       24   54.454125  43.083333       25   57.379812  25.250000       26   94.520833  33.958333       27   49.693854  27.500000       28    2.406438  46.916667       29    7.133833  53.916667       30    7.829167  51.500000       31    5.584646  55.791667 

i split dataframe apart 12 different data frames, 1 each month, problem different lengths because amount of days in month vary, meaning attempts @ using np.array_split have failed. how can split based on month index?

one solution :

df=result_gb_daily_average  [df.iloc[df.index.get_level_values('month')==i+1] in range(12)]  

or, shorter:

[df.ix[i] in range(12)] 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -