【发布时间】:2017-06-06 11:36:19
【问题描述】:
我有一个包含日期的数据框,我想按如下方式处理数据以进行特征工程
df
date
2016/1/1
2015/2/10
2016/4/5
处理后我想让df看起来像
date Jan Feb Mar Apr
2016/1/1 30 0 0 0 //date from 1/1 to 1/30 : the number of dates in jan
2015/2/10 0 19 11 0 //date from 2/10 to 3/11 : the number of dates in feb and no of dates in mar
2016/3/25 0 0 7 21 //date from 3/25 to 4/21 : the number of dates in mar and no of dates in apr
-
获取 df["date"] 后 30 天
df["date"] + timedelta(month=1)
统计属于特定 30 天的月份的频率
有什么方法可以快速做到这一点?
谢谢。
【问题讨论】:
-
到目前为止你尝试了什么?
-
你好 @MrGrj ,只能想到 31 - df["date"].date 来获取休息日,然后使用 30- 休息日来获取下个月的天数。但不要知道如何将它们自动放入列中