本文整理汇总了Python中pandas.core.frame.DataFrame.shift方法的典型用法代码示例。如果您正苦于以下问题:Python DataFrame.shift方法的具体用法?Python DataFrame.shift怎么用?Python DataFrame.shift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.frame.DataFrame
的用法示例。
在下文中一共展示了DataFrame.shift方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: shift
# 需要导入模块: from pandas.core.frame import DataFrame [as 别名]
# 或者: from pandas.core.frame.DataFrame import shift [as 别名]
def shift(self, periods=1, freq=None, axis='major'):
"""
Shift index by desired number of periods with an optional time freq.
The shifted data will not include the dropped periods and the
shifted axis will be smaller than the original. This is different
from the behavior of DataFrame.shift()
Parameters
----------
periods : int
Number of periods to move, can be positive or negative
freq : DateOffset, timedelta, or time rule string, optional
axis : {'items', 'major', 'minor'} or {0, 1, 2}
Returns
-------
shifted : Panel
"""
if freq:
return self.tshift(periods, freq, axis=axis)
return super(Panel, self).slice_shift(periods, axis=axis)
示例2: shift
# 需要导入模块: from pandas.core.frame import DataFrame [as 别名]
# 或者: from pandas.core.frame.DataFrame import shift [as 别名]
def shift(self, periods=1, freq=None, axis='major'):
"""
Shift index by desired number of periods with an optional time freq.
The shifted data will not include the dropped periods and the
shifted axis will be smaller than the original. This is different
from the behavior of DataFrame.shift()
Parameters
----------
periods : int
Number of periods to move, can be positive or negative
freq : DateOffset, timedelta, or time rule string, optional
axis : {'items', 'major', 'minor'} or {0, 1, 2}
Returns
-------
shifted : Panel
"""
if freq:
return self.tshift(periods, freq, axis=axis)
return super(Panel, self).slice_shift(periods, axis=axis)
示例3: shift
# 需要导入模块: from pandas.core.frame import DataFrame [as 别名]
# 或者: from pandas.core.frame.DataFrame import shift [as 别名]
def shift(self, lags, freq=None, axis='major'):
"""
Shift major or minor axis by specified number of leads/lags. Drops
periods right now compared with DataFrame.shift
Parameters
----------
lags : int
axis : {'major', 'minor'}
Returns
-------
shifted : Panel
"""
values = self.values
items = self.items
major_axis = self.major_axis
minor_axis = self.minor_axis
if freq:
return self.tshift(lags, freq, axis=axis)
if lags > 0:
vslicer = slice(None, -lags)
islicer = slice(lags, None)
elif lags == 0:
vslicer = islicer = slice(None)
else:
vslicer = slice(-lags, None)
islicer = slice(None, lags)
axis = self._get_axis_name(axis)
if axis == 'major_axis':
values = values[:, vslicer, :]
major_axis = major_axis[islicer]
elif axis == 'minor_axis':
values = values[:, :, vslicer]
minor_axis = minor_axis[islicer]
else:
raise ValueError('Invalid axis')
return self._constructor(values, items=items, major_axis=major_axis,
minor_axis=minor_axis)