-
Overview
理解offset in Python
-
pct_change(periods=1, fill_method='pad', limit=None, freq=None, **kwargs)
Percentage change between the current and a prior element.
fill_method
mean how to handle NAs before computing percent changes;limit
also about the NA, mean the number of consecutive NAs to fill before stopping; -
shift(periods=1, freq=None, axis=0, fill_value=<object object>)
Shift index by desired number of periods with an optional time
freq
.When freq is not passed, shift the index without realigning the data.
If freq is passed (in this case, the index must be date or datetime, or it will raise a NotImplementedError), the index will be increased using the periods and the freq.
fill_value
is the scalar value to use newly introduced missing values. The default depends on the dtype of self(np.nan
for numeric data,NaT
for datetime, timedelta, period data)shift() 是针对index进行操作
-
How to use
freq
in shift()?shift()
shifting values withperiods
, and shifting time-series data withfreq
.df.shift(freq='10D') # is equal to df.shift(period=10, freq='D')
-
Summary
针对
shift()
,不要用数据上下移动的思考角度,而是将shift()参数period或freq用于index相加。shift()
是针对index的值进行增减操作的函数,index分为value或time dtype,才会有period
和freq
的区别,freq
的使用要求index的dtype必须为time类型 -
References
理解pct_change()&shift() in Python
最新推荐文章于 2024-04-24 22:52:03 发布