当前位置: 首页>>代码示例>>Python>>正文


Python IntIndex.to_block_index方法代码示例

本文整理汇总了Python中pandas._sparse.IntIndex.to_block_index方法的典型用法代码示例。如果您正苦于以下问题:Python IntIndex.to_block_index方法的具体用法?Python IntIndex.to_block_index怎么用?Python IntIndex.to_block_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas._sparse.IntIndex的用法示例。


在下文中一共展示了IntIndex.to_block_index方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_with_fill_value

# 需要导入模块: from pandas._sparse import IntIndex [as 别名]
# 或者: from pandas._sparse.IntIndex import to_block_index [as 别名]
        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,代码行数:11,代码来源:test_series.py

示例2: shift

# 需要导入模块: from pandas._sparse import IntIndex [as 别名]
# 或者: from pandas._sparse.IntIndex import to_block_index [as 别名]
    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,代码行数:36,代码来源:series.py

示例3: shift

# 需要导入模块: from pandas._sparse import IntIndex [as 别名]
# 或者: from pandas._sparse.IntIndex import to_block_index [as 别名]
    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,代码行数:40,代码来源:series.py

示例4: shift

# 需要导入模块: from pandas._sparse import IntIndex [as 别名]
# 或者: from pandas._sparse.IntIndex import to_block_index [as 别名]
    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,代码行数:39,代码来源:series.py


注:本文中的pandas._sparse.IntIndex.to_block_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。