當前位置: 首頁>>代碼示例>>Python>>正文


Python lib.get_reverse_indexer方法代碼示例

本文整理匯總了Python中pandas._libs.lib.get_reverse_indexer方法的典型用法代碼示例。如果您正苦於以下問題:Python lib.get_reverse_indexer方法的具體用法?Python lib.get_reverse_indexer怎麽用?Python lib.get_reverse_indexer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas._libs.lib的用法示例。


在下文中一共展示了lib.get_reverse_indexer方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: combine

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import get_reverse_indexer [as 別名]
def combine(self, blocks, copy=True):
        """ return a new manager with the blocks """
        if len(blocks) == 0:
            return self.make_empty()

        # FIXME: optimization potential
        indexer = np.sort(np.concatenate([b.mgr_locs.as_array
                                          for b in blocks]))
        inv_indexer = lib.get_reverse_indexer(indexer, self.shape[0])

        new_blocks = []
        for b in blocks:
            b = b.copy(deep=copy)
            b.mgr_locs = algos.take_1d(inv_indexer, b.mgr_locs.as_array,
                                       axis=0, allow_fill=False)
            new_blocks.append(b)

        axes = list(self.axes)
        axes[0] = self.items.take(indexer)

        return self.__class__(new_blocks, axes, do_integrity_check=False) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:managers.py

示例2: test_get_reverse_indexer

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import get_reverse_indexer [as 別名]
def test_get_reverse_indexer(self):
        indexer = np.array([-1, -1, 1, 2, 0, -1, 3, 4], dtype=np.int64)
        result = lib.get_reverse_indexer(indexer, 5)
        expected = np.array([4, 2, 3, 6, 7], dtype=np.int64)
        tm.assert_numpy_array_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_lib.py

示例3: test_get_reverse_indexer

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import get_reverse_indexer [as 別名]
def test_get_reverse_indexer(self):
        indexer = np.array([-1, -1, 1, 2, 0, -1, 3, 4], dtype=np.int64)
        result = lib.get_reverse_indexer(indexer, 5)
        expected = np.array([4, 2, 3, 6, 7], dtype=np.int64)
        assert np.array_equal(result, expected) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:7,代碼來源:test_lib.py

示例4: _sort_levels_monotonic

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import get_reverse_indexer [as 別名]
def _sort_levels_monotonic(self):
        """
        .. versionadded:: 0.20.0

        This is an *internal* function.

        create a new MultiIndex from the current to monotonically sorted
        items IN the levels. This does not actually make the entire MultiIndex
        monotonic, JUST the levels.

        The resulting MultiIndex will have the same outward
        appearance, meaning the same .values and ordering. It will also
        be .equals() to the original.

        Returns
        -------
        MultiIndex

        Examples
        --------

        >>> i = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
                              labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
        >>> i
        MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
                   labels=[[0, 0, 1, 1], [0, 1, 0, 1]])

        >>> i.sort_monotonic()
        MultiIndex(levels=[['a', 'b'], ['aa', 'bb']],
                   labels=[[0, 0, 1, 1], [1, 0, 1, 0]])

        """

        if self.is_lexsorted() and self.is_monotonic:
            return self

        new_levels = []
        new_labels = []

        for lev, lab in zip(self.levels, self.labels):

            if not lev.is_monotonic:
                try:
                    # indexer to reorder the levels
                    indexer = lev.argsort()
                except TypeError:
                    pass
                else:
                    lev = lev.take(indexer)

                    # indexer to reorder the labels
                    indexer = _ensure_int64(indexer)
                    ri = lib.get_reverse_indexer(indexer, len(indexer))
                    lab = algos.take_1d(ri, lab)

            new_levels.append(lev)
            new_labels.append(lab)

        return MultiIndex(new_levels, new_labels,
                          names=self.names, sortorder=self.sortorder,
                          verify_integrity=False) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:63,代碼來源:multi.py

示例5: _sort_levels_monotonic

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import get_reverse_indexer [as 別名]
def _sort_levels_monotonic(self):
        """
        .. versionadded:: 0.20.0

        This is an *internal* function.

        create a new MultiIndex from the current to monotonically sorted
        items IN the levels. This does not actually make the entire MultiIndex
        monotonic, JUST the levels.

        The resulting MultiIndex will have the same outward
        appearance, meaning the same .values and ordering. It will also
        be .equals() to the original.

        Returns
        -------
        MultiIndex

        Examples
        --------

        >>> i = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
                              labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
        >>> i
        MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
                   labels=[[0, 0, 1, 1], [0, 1, 0, 1]])

        >>> i.sort_monotonic()
        MultiIndex(levels=[['a', 'b'], ['aa', 'bb']],
                   labels=[[0, 0, 1, 1], [1, 0, 1, 0]])

        """

        if self.is_lexsorted() and self.is_monotonic:
            return self

        new_levels = []
        new_labels = []

        for lev, lab in zip(self.levels, self.labels):

            if lev.is_monotonic:
                new_levels.append(lev)
                new_labels.append(lab)
                continue

            # indexer to reorder the levels
            indexer = lev.argsort()
            lev = lev.take(indexer)

            # indexer to reorder the labels
            indexer = _ensure_int64(indexer)
            ri = lib.get_reverse_indexer(indexer, len(indexer))
            lab = algos.take_1d(ri, lab)

            new_levels.append(lev)
            new_labels.append(lab)

        return MultiIndex(new_levels, new_labels,
                          names=self.names, sortorder=self.sortorder,
                          verify_integrity=False) 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:63,代碼來源:multi.py


注:本文中的pandas._libs.lib.get_reverse_indexer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。