【发布时间】:2017-08-21 16:10:15
【问题描述】:
我一直在寻找是否可以使用在pandas 中索引的date 创建假人,但还没有找到任何东西。
我有一个由date 索引的df
dew temp
date
2010-01-02 00:00:00 129.0 -16
2010-01-02 01:00:00 148.0 -15
2010-01-02 02:00:00 159.0 -11
2010-01-02 03:00:00 181.0 -7
2010-01-02 04:00:00 138.0 -7
...
我知道我可以使用,将date 设置为列,
df.reset_index(level=0, inplace=True)
然后使用类似的东西来创建假人,
df['main_hours'] = np.where((df['date'] >= '2010-01-02 03:00:00') & (df['date'] <= '2010-01-02 05:00:00')1,0)
但是,我想在不使用 date 作为列的情况下使用索引 date 即时创建虚拟变量。 pandas 有这样的方法吗?
任何建议将不胜感激。
【问题讨论】:
-
您的预期输出是什么?你想要虚拟的只是时间,还是日期?
-
标签: python pandas indexing dummy-variable