在熊猫时间序列/日期功能中设置频率

时间:2017-11-10 15:17:30

标签: python pandas datetime

在熊猫中设置Time Series / Date functionality的频率时,使用大写字母或小写字母是否相同?

使用freq ='d'或freq ='D'是否相同?

Offset Aliases

A number of string aliases are given to useful common time series frequencies. We will refer to these aliases as offset aliases.

Alias   Description
B   business day frequency
C   custom business day frequency
D   calendar day frequency
W   weekly frequency
M   month end frequency
SM  semi-month end frequency (15th and end of month)
BM  business month end frequency
CBM custom business month end frequency
MS  month start frequency
SMS semi-month start frequency (1st and 15th)
BMS business month start frequency
CBMS    custom business month start frequency
Q   quarter end frequency
BQ  business quarter end frequency
QS  quarter start frequency
BQS business quarter start frequency
A, Y    year end frequency
BA, BY  business year end frequency
AS, YS  year start frequency
BAS, BYS    business year start frequency
BH  business hour frequency
H   hourly frequency
T, min  minutely frequency
S   secondly frequency
L, ms   milliseconds
U, us   microseconds
N   nanoseconds

1 个答案:

答案 0 :(得分:2)

在文档中,所有值都是大写,请检查offset-aliases

我尝试小检查是否相同:

L= ['B','D','W','M','Q','H','T','S']

rng = pd.date_range('2017-04-03', periods=10)
df = pd.DataFrame({'a': range(10)}, index=rng)  
print (df)

for x in L:
    a  = df.resample(x.lower()).ffill() 
    b = df.resample(x).ffill()
    print ((a == b).all())

a    True
dtype: bool
a    True
dtype: bool
a    True
dtype: bool
a    True
dtype: bool
a    True
dtype: bool
a    True
dtype: bool
a    True
dtype: bool
a    True
dtype: bool