Python pandas.core.algorithms.diff() Examples

The following are 13 code examples of pandas.core.algorithms.diff(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.core.algorithms , or try the search function .
Example #1
Source File: blocks.py    From recruit with Apache License 2.0 5 votes vote down vote up
def diff(self, n, axis=1):
        """ return block for the diff of the values """
        new_values = algos.diff(self.values, n, axis=axis)
        return [self.make_block(values=new_values)] 
Example #2
Source File: blocks.py    From recruit with Apache License 2.0 5 votes vote down vote up
def diff(self, n, axis=0):
        """1st discrete difference

        Parameters
        ----------
        n : int, number of periods to diff
        axis : int, axis to diff upon. default 0

        Return
        ------
        A list with a new TimeDeltaBlock.

        Note
        ----
        The arguments here are mimicking shift so they are called correctly
        by apply.
        """
        if axis == 0:
            # Cannot currently calculate diff across multiple blocks since this
            # function is invoked via apply
            raise NotImplementedError
        new_values = (self.values - self.shift(n, axis=axis)[0].values).asi8

        # Reshape the new_values like how algos.diff does for timedelta data
        new_values = new_values.reshape(1, len(new_values))
        new_values = new_values.astype('timedelta64[ns]')
        return [TimeDeltaBlock(new_values, placement=self.mgr_locs.indexer)] 
Example #3
Source File: internals.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def diff(self, n, axis=1, mgr=None):
        """ return block for the diff of the values """
        new_values = algos.diff(self.values, n, axis=axis)
        return [self.make_block(values=new_values)] 
Example #4
Source File: internals.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def diff(self, n, axis=0, mgr=None):
        """1st discrete difference

        Parameters
        ----------
        n : int, number of periods to diff
        axis : int, axis to diff upon. default 0
        mgr : default None

        Return
        ------
        A list with a new TimeDeltaBlock.

        Note
        ----
        The arguments here are mimicking shift so they are called correctly
        by apply.
        """
        if axis == 0:
            # Cannot currently calculate diff across multiple blocks since this
            # function is invoked via apply
            raise NotImplementedError
        new_values = (self.values - self.shift(n, axis=axis)[0].values).asi8

        # Reshape the new_values like how algos.diff does for timedelta data
        new_values = new_values.reshape(1, len(new_values))
        new_values = new_values.astype('timedelta64[ns]')
        return [TimeDeltaBlock(new_values, placement=self.mgr_locs.indexer)] 
Example #5
Source File: internals.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def diff(self, **kwargs):
        return self.apply('diff', **kwargs) 
Example #6
Source File: blocks.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def diff(self, n, axis=1):
        """ return block for the diff of the values """
        new_values = algos.diff(self.values, n, axis=axis)
        return [self.make_block(values=new_values)] 
Example #7
Source File: blocks.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def diff(self, n, axis=0):
        """1st discrete difference

        Parameters
        ----------
        n : int, number of periods to diff
        axis : int, axis to diff upon. default 0

        Return
        ------
        A list with a new TimeDeltaBlock.

        Note
        ----
        The arguments here are mimicking shift so they are called correctly
        by apply.
        """
        if axis == 0:
            # Cannot currently calculate diff across multiple blocks since this
            # function is invoked via apply
            raise NotImplementedError
        new_values = (self.values - self.shift(n, axis=axis)[0].values).asi8

        # Reshape the new_values like how algos.diff does for timedelta data
        new_values = new_values.reshape(1, len(new_values))
        new_values = new_values.astype('timedelta64[ns]')
        return [TimeDeltaBlock(new_values, placement=self.mgr_locs.indexer)] 
Example #8
Source File: series.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def diff(self, periods=1):
        """
        1st discrete difference of object

        Parameters
        ----------
        periods : int, default 1
            Periods to shift for forming difference

        Returns
        -------
        diffed : Series
        """
        result = algorithms.diff(_values_from_object(self), periods)
        return self._constructor(result, index=self.index).__finalize__(self) 
Example #9
Source File: internals.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def diff(self, n, axis=1, mgr=None):
        """ return block for the diff of the values """
        new_values = algos.diff(self.values, n, axis=axis)
        return [self.make_block(values=new_values, fastpath=True)] 
Example #10
Source File: internals.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def diff(self, **kwargs):
        return self.apply('diff', **kwargs) 
Example #11
Source File: series.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def diff(self, periods=1):
        """
        1st discrete difference of object

        Parameters
        ----------
        periods : int, default 1
            Periods to shift for forming difference

        Returns
        -------
        diffed : Series
        """
        result = algorithms.diff(_values_from_object(self), periods)
        return self._constructor(result, index=self.index).__finalize__(self) 
Example #12
Source File: internals.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def diff(self, n, axis=1, mgr=None):
        """ return block for the diff of the values """
        new_values = algos.diff(self.values, n, axis=axis)
        return [self.make_block(values=new_values, fastpath=True)] 
Example #13
Source File: internals.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def diff(self, **kwargs):
        return self.apply('diff', **kwargs)