featuretools.primitives.DistanceToHoliday#
- class featuretools.primitives.DistanceToHoliday(holiday="New Year's Day", country='US')[source]#
计算距离指定假日的天数.
- Description:
对于一个日期列表,返回距离最近一次指定假日的天数. 天数以天为单位返回.如果最近的假日发生在给定日期之前, 则返回一个负数.
如果日期缺失,则返回 NaN.
目前仅支持1950年至2100年之间的日期.
- Parameters:
holiday (str) – 假日的名称.默认为元旦.
country (str) – 指定使用哪个国家的日历来确定假日. 默认为 US.
Examples
>>> from datetime import datetime >>> distance_to_holiday = DistanceToHoliday("New Year's Day") >>> dates = [datetime(2010, 1, 1), ... datetime(2012, 5, 31), ... datetime(2017, 7, 31), ... datetime(2020, 12, 31)] >>> distance_to_holiday(dates).tolist() [0, -151, 154, 1]
我们还可以控制搜索假日的国家.
>>> distance_to_holiday = DistanceToHoliday("Canada Day", country='Canada') >>> dates = [datetime(2010, 1, 1), ... datetime(2012, 5, 31), ... datetime(2017, 7, 31), ... datetime(2020, 12, 31)] >>> distance_to_holiday(dates).tolist() [181, 31, -30, 182]
Methods
__init__([holiday, country])flatten_nested_input_types(input_types)将嵌套的列模式输入展平成一个列表.
generate_name(base_feature_names)generate_names(base_feature_names)get_args_string()get_arguments()get_description(input_column_descriptions[, ...])get_filepath(filename)get_function()Attributes
base_ofbase_of_excludecommutativedefault_valueDefault value this feature returns if no data found.
description_templateinput_typeswoodwork.ColumnSchema types of inputs
max_stack_depthnameName of the primitive
number_output_featuresNumber of columns in feature matrix associated with this feature
return_typeColumnSchema type of return
stack_onstack_on_excludestack_on_selfuses_calc_timeuses_full_dataframe