Pandas 按日期或匿名函数筛选熊猫系列

Pandas 按日期或匿名函数筛选熊猫系列,pandas,numpy,matplotlib,Pandas,Numpy,Matplotlib,我有一个类型的对象:“pandas.core.series.series” 看起来是这样的: 1997-09-10 0.000000 1997-09-11 0.000000 1997-09-12 0.000000 ... 2019-10-15 348153.430102 2019-10-16 348153.265395 2019-10-17 348153.100689 Freq: B

我有一个类型的对象:“pandas.core.series.series”

看起来是这样的:

1997-09-10         0.000000
1997-09-11         0.000000
1997-09-12         0.000000
                  ...      
2019-10-15    348153.430102
2019-10-16    348153.265395
2019-10-17    348153.100689
Freq: B, Length: 5767, dtype: float64
我想把它过滤到2005-01-01之后的结果中

我已经研究了Series.filter函数,但它们没有给出如何与日期或匿名函数交互的示例

请告知。

使用:

rng = pd.date_range('2004-12-28', periods=10)
s = pd.Series( range(10), index=rng)  
print (s)
2004-12-28    0
2004-12-29    1
2004-12-30    2
2004-12-31    3
2005-01-01    4
2005-01-02    5
2005-01-03    6
2005-01-04    7
2005-01-05    8
2005-01-06    9
Freq: D, dtype: int64
如果需要,请使用还包括日期时间:

print (s.loc['2005-01-01':])
2005-01-01    4
2005-01-02    5
2005-01-03    6
2005-01-04    7
2005-01-05    8
2005-01-06    9
Freq: D, dtype: int64
或与“按日期时间比较”一起使用:

#include datetime   
print (s[s.index >= '2005-01-01'])
2005-01-01    4
2005-01-02    5
2005-01-03    6
2005-01-04    7
2005-01-05    8
2005-01-06    9
Freq: D, dtype: int64

#exlude datetime
print (s[s.index > '2005-01-01'])
2005-01-02    5
2005-01-03    6
2005-01-04    7
2005-01-05    8
2005-01-06    9
Freq: D, dtype: int64
我们可以简单地做到:

s[s.index>'2005-01-01']
或:


序列datetime数据类型中的索引是否为?
s.loc[lambda x: x.index>'2005-01-01']