|
38 | 38 | import numpy as np |
39 | 39 | import pandas as pd |
40 | 40 | from pandas.tseries.frequencies import to_offset |
| 41 | +from pandas.api.types import is_numeric_dtype |
41 | 42 | import logging |
42 | 43 | import importlib.resources |
43 | 44 |
|
@@ -91,9 +92,18 @@ def load_BDEW_style_profiles(source_file, weather_data, cfg, houses_dict, |
91 | 92 | skiprows=[0], header=[0, 1], index_col=[0], |
92 | 93 | skipfooter=1, |
93 | 94 | ) |
94 | | - weather_daily = (weather_data.resample('D', label='right', closed='right') |
95 | | - .mean(numeric_only=True)) |
96 | | - # print(weather_daily) |
| 95 | + |
| 96 | + agg_dict = dict() |
| 97 | + for col in weather_data.columns: |
| 98 | + if is_numeric_dtype(weather_data[col]): |
| 99 | + agg_dict[col] = 'mean' |
| 100 | + else: |
| 101 | + agg_dict[col] = 'first' |
| 102 | + |
| 103 | + weather_daily = (weather_data |
| 104 | + .shift(periods=-1, freq="infer") |
| 105 | + .resample('D', label='left', closed='left') |
| 106 | + .agg(agg_dict)) |
97 | 107 |
|
98 | 108 | houses_list = settings['houses_list_BDEW'] |
99 | 109 | multiindex = pd.MultiIndex.from_product([houses_list, [energy_type]], |
@@ -127,12 +137,8 @@ def load_BDEW_style_profiles(source_file, weather_data, cfg, houses_dict, |
127 | 137 | profile_year = pd.Series(dtype='float') |
128 | 138 | profiles_daily = [] |
129 | 139 | for date in weather_daily.index: |
130 | | - weekday = weather_data.loc[date]['weekday_BDEW'] |
131 | | - season = weather_data.loc[date]['season_BDEW'] |
132 | | - # Important: In order identify the weekday of the resampled days, |
133 | | - # we labled them 'right'. From now on we need the label 'left', |
134 | | - # so we substract '1 day' from each date: |
135 | | - date -= pd.Timedelta('1 day') |
| 140 | + weekday = weather_daily.loc[date]['weekday_BDEW'] |
| 141 | + season = weather_daily.loc[date]['season_BDEW'] |
136 | 142 |
|
137 | 143 | source_profile = source_df[house_type][season, weekday] |
138 | 144 |
|
|
0 commit comments