in fclib/fclib/feature_engineering/feature_utils.py [0:0]
def normalized_current_datehour(datetime_col, min_datehour, max_datehour):
"""
Temporal feature indicating the position of the hour of a record in the
entire time period under consideration, normalized to be between 0 and 1.
Args:
datetime_col: Datetime column.
min_datehour: minimum value of datehour.
max_datehour: maximum value of datehour.
Returns:
float: the position of the current datehour in the min_datehour:max_datehour range
"""
current_datehour = (datetime_col - min_datehour).apply(lambda x: x.days * 24 + x.seconds / 3600)
max_min_diff = max_datehour - min_datehour
if max_min_diff != 0:
current_datehour = current_datehour / (max_min_diff.days * 24 + max_min_diff.seconds / 3600)
else:
current_datehour = pd.Series([0 for x in range(len(datetime_col))])
return current_datehour