如何比较熊猫的频率/采样率?

时间:2014-07-08 15:23:27

标签: python pandas sample-data

有没有办法说' 13Min'是> ' 59S'和<' 2H'在熊猫中使用频率表示法?

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:1)

另一种方法是将两个频率都添加到一个公共日期,并比较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