def query_datebydelta(base_date, delta):
# -- assert type(base_date) == pandas._libs.tslibs.timestamps.Timestamp
return base_date + datetime.timedelta(days=delta)
仅作记录
用法:
df['Turnover_10daysbeforebuy'] = df.apply(lambda x: query_J2Turnover(x['stock_code'], start_date=x['date_10daysbeforebuy'], end_date=query_datebydelta(x['date_buy'], -1)).mean(), axis=1)
query_datebydelta(x['date_buy'], -1)
query_datebydelta(x['date_buy'], -1)
查询前一天的日期
query_datebydelta(x['date_buy'], 1)
查询后一天的日期