Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pandas timeseries选择所有记录<;=日期时间_Python_Pandas - Fatal编程技术网

Python pandas timeseries选择所有记录<;=日期时间

Python pandas timeseries选择所有记录<;=日期时间,python,pandas,Python,Pandas,我试图选择timeseries的一个子集,其中dateindex应该小于给定的日期 rng = pd.date_range(datetime.date(2013,1,1), datetime.date(2014,1,1), freq='M') ts = pd.TimeSeries(range(len(rng)),index=rng) ts[ts < datetime.date(2013,8,1)] rng=pd.date\u范围(datetime.date(2013,1,1),datet

我试图选择timeseries的一个子集,其中dateindex应该小于给定的日期

rng = pd.date_range(datetime.date(2013,1,1), datetime.date(2014,1,1), freq='M')
ts = pd.TimeSeries(range(len(rng)),index=rng)
ts[ts < datetime.date(2013,8,1)]
rng=pd.date\u范围(datetime.date(2013,1,1),datetime.date(2014,1,1),freq='M')
ts=pd.TimeSeries(范围(len(rng)),索引=rng)
ts[ts

这会引发异常
TypeError:无法将datetime.date与int进行比较。你知道如何解决这个问题吗?

你的最后一行将
ts
中的值与
datetime.date
进行比较。这就是为什么在无序类型中出现TypeError

In [31]: ts[ts.index < np.datetime64('2013-08-01')]
Out[31]: 
2013-01-31    0
2013-02-28    1
2013-03-31    2
2013-04-30    3
2013-05-31    4
2013-06-30    5
2013-07-31    6
Freq: M, dtype: int64

爱你的第二个解决方案!谢谢
In [33]: ts[:'2013-08-01']
Out[33]: 
2013-01-31    0
2013-02-28    1
2013-03-31    2
2013-04-30    3
2013-05-31    4
2013-06-30    5
2013-07-31    6
Freq: M, dtype: int64