有没有办法说 '13Min' 是 > '59S' 和 <'2H' 使用熊猫中的频率符号?
问问题
1138 次
2 回答
5
In [4]: from pandas.tseries.frequencies import to_offset
In [5]: to_offset('59s') < to_offset('1T')
Out[5]: True
In [6]: to_offset('13T') > to_offset('59s')
Out[6]: True
In [7]: to_offset('13T') < to_offset('59s')
Out[7]: False
In [8]: to_offset('13T') > to_offset('2H')
Out[8]: False
In [10]: to_offset('13T') < to_offset('2H')
Out[10]: True
于 2014-07-08T15:30:51.280 回答
3
另一种方法是将两个频率添加到一个公共日期并比较Timestamp
. 这也解决了@rixmit的评论。
In [2]: import pandas as pd
In [3]: from pandas.tseries.frequencies import to_offset
In [4]: common_dt = pd.to_datetime("2000-01-01")
In [5]: f_a = common_dt + to_offset('59s')
In [6]: f_b = common_dt + to_offset('1T')
In [7]: f_a > f_b
Out[8]: False
In [9]: f_a = common_dt + to_offset('M')
In [9]: f_b = common_dt + to_offset('W')
In [10]: f_a > f_b
Out[10]: True
于 2018-07-02T10:43:49.413 回答