mars.dataframe.Series.shift#
- Series.shift(periods=1, freq=None, axis=0, fill_value=None)#
将索引移动到所需的周期数,并可选地指定时间freq。
当freq未传递时,移动索引而不重新对齐数据。 如果传递了freq(在这种情况下,索引必须是日期或日期时间,否则将引发NotImplementedError),将使用周期和freq增加索引。
- Parameters
periods (int) – 移动的周期数量。可以是正数或负数。
freq (DateOffset, tseries.offsets, timedelta, 或 str, 可选) – 使用来自tseries模块或时间规则的偏移量(例如‘EOM’)。 如果freq被指定,则索引值会发生偏移,但数据不被重新对齐。也就是说,如果您想在偏移时扩展索引并保留原始数据,请使用freq。
axis ({0 或 'index', 1 或 'columns', None}, 默认 None) – 移动方向。
fill_value (object, optional) – 用于新引入的缺失值的标量值。 默认值取决于self的dtype。 对于数值数据,使用
np.nan。 对于日期时间、时间间隔或周期数据等,使用NaT。 对于扩展dtype,使用self.dtype.na_value。
- Returns
输入对象的拷贝,已偏移。
- Return type
另请参阅
Index.shift移动索引的值。
DatetimeIndex.shift移动DatetimeIndex的值。
PeriodIndex.shift移动 PeriodIndex 的值。
tshift移动时间索引,如果可用则使用索引的频率。
示例
>>> import mars.dataframe as md
>>> df = md.DataFrame({'Col1': [10, 20, 15, 30, 45], ... 'Col2': [13, 23, 18, 33, 48], ... 'Col3': [17, 27, 22, 37, 52]})
>>> df.shift(periods=3).execute() Col1 Col2 Col3 0 NaN NaN NaN 1 NaN NaN NaN 2 NaN NaN NaN 3 10.0 13.0 17.0 4 20.0 23.0 27.0
>>> df.shift(periods=1, axis='columns').execute() Col1 Col2 Col3 0 NaN 10.0 13.0 1 NaN 20.0 23.0 2 NaN 15.0 18.0 3 NaN 30.0 33.0 4 NaN 45.0 48.0
>>> df.shift(periods=3, fill_value=0).execute() Col1 Col2 Col3 0 0 0 0 1 0 0 0 2 0 0 0 3 10 13 17 4 20 23 27