@@ -189,7 +189,7 @@ def add_station_features(df: pd.DataFrame):
189189 """
190190 stations = df .index .get_level_values ("station" )
191191 for station in stations .unique ():
192- df [f"station={ station } " ] = 1 * (stations == station )
192+ df [f"station={ station } " ] = (stations == station ). astype ( float )
193193 return df
194194
195195
@@ -208,15 +208,9 @@ def add_datetime_features(df: pd.DataFrame):
208208 dataframe with missing values
209209 """
210210
211- time = np .concatenate (
212- [
213- np .cos (2 * np .pi * np .arange (60 , 366 ) / 365 ),
214- np .cos (2 * np .pi * np .arange (1 , 366 ) / 365 ),
215- np .cos (2 * np .pi * np .arange (1 , 366 ) / 365 ),
216- np .cos (2 * np .pi * np .arange (1 , 367 ) / 366 ),
217- np .cos (2 * np .pi * np .arange (1 , 60 ) / 365 ),
218- ]
211+ time = df .index .get_level .values ("datetime" )
212+ days_in_year = time .dt .year .apply (
213+ lambda x : 366 if ((x % 4 == 0 ) and (x % 100 != 0 )) or (x % 400 == 0 ) else 365
219214 )
220- for i_station , (station , dfs ) in enumerate (df .groupby ("station" )):
221- df .loc [station , "Time" ] = time
215+ df ["time_cos" ] = np .cos (2 * np .pi * time .dt .dayofyear / days_in_year )
222216 return df
0 commit comments