问题描述
[这是数据表的图片][1]
解决方法
最好跨行使用 DataFrame.apply()
(booking_check_in
)。
生成从 booking_check_out
到 zip()
的 date_range()
和 def average_by_date(row):
dates = pd.date_range(row.booking_check_in,row.booking_check_out).strftime('%Y-%m-%d')[:-1]
averages = [row.average] * len(dates)
return dict(zip(dates,averages))
grup_usd['average_by_date'] = grup_usd.apply(average_by_date,axis=1)
# booking_check_in booking_check_out booking_earned diff_day_int average average_by_date
# 0 2019-11-01 2019-11-02 48.0 1 48.0 {'2019-11-01': 48.0}
# 1 2019-11-01 2019-11-04 96.0 3 32.0 {'2019-11-01': 32.0,'2019-11-02': 32.0,'2019...
# 2 2019-11-01 2019-11-02 50.0 1 50.0 {'2019-11-01': 50.0}
# 3 2019-11-01 2019-11-05 252.0 4 63.0 {'2019-11-01': 63.0,'2019-11-02': 63.0,'2019...
它们的平均值:
Warning: Received `true` for a non-boolean attribute `active`.