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


Python _sparse.IntIndex類代碼示例

本文整理匯總了Python中pandas._sparse.IntIndex的典型用法代碼示例。如果您正苦於以下問題:Python IntIndex類的具體用法?Python IntIndex怎麽用?Python IntIndex使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: shift

    def shift(self, periods, freq=None):
        """
        Analogous to Series.shift
        """

        # no special handling of fill values yet
        if not isnull(self.fill_value):
            # TODO: kwds is not defined...should this work?
            dense_shifted = self.to_dense().shift(periods, freq=freq, **kwds)  # noqa
            return dense_shifted.to_sparse(fill_value=self.fill_value,
                                           kind=self.kind)

        if periods == 0:
            return self.copy()

        if freq is not None:
            return self._constructor(
                self.sp_values, sparse_index=self.sp_index,
                index=self.index.shift(periods, freq),
                fill_value=self.fill_value).__finalize__(self)

        int_index = self.sp_index.to_int_index()
        new_indices = int_index.indices + periods
        start, end = new_indices.searchsorted([0, int_index.length])

        new_indices = new_indices[start:end]

        new_sp_index = IntIndex(len(self), new_indices)
        if isinstance(self.sp_index, BlockIndex):
            new_sp_index = new_sp_index.to_block_index()

        return self._constructor(self.sp_values[start:end].copy(),
                                 index=self.index, sparse_index=new_sp_index,
                                 fill_value=self.fill_value).__finalize__(self)
開發者ID:Umairmooc,項目名稱:pandas,代碼行數:34,代碼來源:series.py

示例2: _check_with_fill_value

        def _check_with_fill_value(values, first, second, fill_value=nan):
            i_index1 = IntIndex(length, first)
            i_index2 = IntIndex(length, second)

            b_index1 = i_index1.to_block_index()
            b_index2 = i_index2.to_block_index()

            _check(values, i_index1, i_index2, fill_value)
            _check(values, b_index1, b_index2, fill_value)
開發者ID:jcfr,項目名稱:pandas,代碼行數:9,代碼來源:test_series.py

示例3: shift

    def shift(self, periods, freq=None, **kwds):
        """
        Analogous to Series.shift
        """
        from pandas.core.datetools import _resolve_offset

        offset = _resolve_offset(freq, kwds)

        # no special handling of fill values yet
        if not isnull(self.fill_value):
            dense_shifted = self.to_dense().shift(periods, freq=freq,
                                                  **kwds)
            return dense_shifted.to_sparse(fill_value=self.fill_value,
                                           kind=self.kind)

        if periods == 0:
            return self.copy()

        if offset is not None:
            return self._constructor(self.sp_values,
                                     sparse_index=self.sp_index,
                                     index=self.index.shift(periods, offset),
                                     fill_value=self.fill_value).__finalize__(self)

        int_index = self.sp_index.to_int_index()
        new_indices = int_index.indices + periods
        start, end = new_indices.searchsorted([0, int_index.length])

        new_indices = new_indices[start:end]

        new_sp_index = IntIndex(len(self), new_indices)
        if isinstance(self.sp_index, BlockIndex):
            new_sp_index = new_sp_index.to_block_index()

        return self._constructor(self.sp_values[start:end].copy(),
                                 index=self.index,
                                 sparse_index=new_sp_index,
                                 fill_value=self.fill_value).__finalize__(self)
開發者ID:5i7788,項目名稱:pandas,代碼行數:38,代碼來源:series.py

示例4: shift

    def shift(self, periods, offset=None, timeRule=None):
        """
        Analogous to Series.shift
        """
        # no special handling of fill values yet
        if not isnull(self.fill_value):
            dense_shifted = self.to_dense().shift(periods, offset=offset,
                                                  timeRule=timeRule)
            return dense_shifted.to_sparse(fill_value=self.fill_value,
                                           kind=self.kind)

        if periods == 0:
            return self.copy()

        if timeRule is not None and offset is None:
            offset = datetools.getOffset(timeRule)

        if offset is not None:
            return SparseSeries(self.sp_values,
                                sparse_index=self.sp_index,
                                index=self.index.shift(periods, offset),
                                fill_value=self.fill_value)

        int_index = self.sp_index.to_int_index()
        new_indices = int_index.indices + periods
        start, end = new_indices.searchsorted([0, int_index.length])

        new_indices = new_indices[start:end]

        new_sp_index = IntIndex(len(self), new_indices)
        if isinstance(self.sp_index, BlockIndex):
            new_sp_index = new_sp_index.to_block_index()

        return SparseSeries(self.sp_values[start:end].copy(),
                            index=self.index,
                            sparse_index=new_sp_index,
                            fill_value=self.fill_value)
開發者ID:gwtaylor,項目名稱:pandas,代碼行數:37,代碼來源:series.py

示例5: test_to_int_index

 def test_to_int_index(self):
     index = IntIndex(10, [2, 3, 4, 5, 6])
     self.assertIs(index.to_int_index(), index)
開發者ID:Acanthostega,項目名稱:pandas,代碼行數:3,代碼來源:test_libsparse.py

示例6: test_equals

 def test_equals(self):
     index = IntIndex(10, [0, 1, 2, 3, 4])
     self.assert_(index.equals(index))
     self.assert_(not index.equals(IntIndex(10, [0, 1, 2, 3])))
開發者ID:Acanthostega,項目名稱:pandas,代碼行數:4,代碼來源:test_libsparse.py

示例7: test_equals

 def test_equals(self):
     index = IntIndex(10, [0, 1, 2, 3, 4])
     self.assertTrue(index.equals(index))
     self.assertFalse(index.equals(IntIndex(10, [0, 1, 2, 3])))
開發者ID:Garrett-R,項目名稱:pandas,代碼行數:4,代碼來源:test_libsparse.py


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