作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试根据日期将数据框分成两个。此处已解决相关问题:Split dataframe into two on the basis of date
我的数据框如下所示:
abcde col_b
2008-04-10 0.041913 0.227050
2008-04-11 0.041372 0.228116
2008-04-12 0.040835 0.229199
2008-04-13 0.040300 0.230301
2008-04-14 0.039770 0.231421
df.loc[pd.to_datetime(df.index) <= split_date]
split_date
是
datetime.date(2008-04-12)
,我收到此错误:
*** TypeError: <class 'datetime.date'> type object 2008-04-12
最佳答案
从你的代码
where split_date is datetime.date(2008-04-12), I get this error
datetime.date()
将参数作为格式
2008,4,12
for more .所以你应该写
split_date = datetime.date(2008,4,12)
df[(pd.to_datetime(df[df.columns[0]]) < split_date)]
"date"
或任何你想要的
df[(pd.to_datetime(df["date"]) < split_date)]
TypeError: <class 'datetime.date'> type object 2008-04-12
datetime object
到系列
df
关于python - 根据日期拆分数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46230864/
我是一名优秀的程序员,十分优秀!