我正在尝试根据日期将数据帧拆分为两个部分。这个问题在这里的相关问题中已经解决: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
我该如何按日期拆分它(例如在2008年04月12日之前和之后)?当我尝试这样做:
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