Python在日期索引中的位置

Python在日期索引中的位置,python,pandas,Python,Pandas,我正试图根据一个日期(即索引)拆分我的数据帧。我的数据如下所示: print(df.head()) date_time value anomaly 2014-11-23 00:00:00 0.414183 0 2014-11-23 01:00:00 0.526574 0 2014-11-23 02:00:00 0.734324 1 到目前为止,我的代码是:

我正试图根据一个日期(即索引)拆分我的数据帧。我的数据如下所示:

  print(df.head())

  date_time             value   anomaly                         
  2014-11-23 00:00:00   0.414183    0   
  2014-11-23 01:00:00   0.526574    0
  2014-11-23 02:00:00   0.734324    1
到目前为止,我的代码是:

 df_split = df.where(df.index >= '2014-11-23 01:00:00')
我期望的结果是:

  2014-11-23 01:00:00   0.526574    0
  2014-11-23 02:00:00   0.734324    1
我的错误是:

  ValueError: Array conditional must be same shape as self
你需要:

如果中的值已排序,请使用:



您应该能够
df_split=df.loc[df.index>='2014-11-23 01:00:00']
df_split = df[df.index >= '2014-11-23 01:00:00']
print (df_split)
                        value  anomaly
date_time                             
2014-11-23 01:00:00  0.526574        0
2014-11-23 02:00:00  0.734324        1
df_split = df.loc['2014-11-23 01:00:00':]
print (df_split)
                        value  anomaly
date_time                             
2014-11-23 01:00:00  0.526574        0
2014-11-23 02:00:00  0.734324        1
df_split = df['2014-11-23 01:00:00':]
print (df_split)
                        value  anomaly
date_time                             
2014-11-23 01:00:00  0.526574        0
2014-11-23 02:00:00  0.734324        1