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


Python internals.SingleBlockManager方法代码示例

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


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

示例1: _unpickle_series_compat

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _unpickle_series_compat(self, state):

        nd_state, own_state = state

        # recreate the ndarray
        data = np.empty(nd_state[1], dtype=nd_state[2])
        np.ndarray.__setstate__(data, nd_state)

        index, fill_value, sp_index = own_state[:3]
        name = None
        if len(own_state) > 3:
            name = own_state[3]

        # create a sparse array
        if not isinstance(data, SparseArray):
            data = SparseArray(data, sparse_index=sp_index,
                               fill_value=fill_value, copy=False)

        # recreate
        data = SingleBlockManager(data, index, fastpath=True)
        generic.NDFrame.__init__(self, data)

        self._set_axis(0, index)
        self.name = name 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:series.py

示例2: sparse_reindex

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def sparse_reindex(self, new_index):
        """
        Conform sparse values to new SparseIndex

        Parameters
        ----------
        new_index : {BlockIndex, IntIndex}

        Returns
        -------
        reindexed : SparseSeries
        """
        if not isinstance(new_index, splib.SparseIndex):
            raise TypeError('new index must be a SparseIndex')

        block = self.block.sparse_reindex(new_index)
        new_data = SingleBlockManager(block, self.index)
        return self._constructor(new_data, index=self.index,
                                 sparse_index=new_index,
                                 fill_value=self.fill_value).__finalize__(self) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:series.py

示例3: _unpickle_series_compat

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _unpickle_series_compat(self, state):

        nd_state, own_state = state

        # recreate the ndarray
        data = np.empty(nd_state[1], dtype=nd_state[2])
        np.ndarray.__setstate__(data, nd_state)

        index, fill_value, sp_index = own_state[:3]
        name = None
        if len(own_state) > 3:
            name = own_state[3]

        # create a sparse array
        if not isinstance(data, SparseArray):
            data = SparseArray(
                data, sparse_index=sp_index, fill_value=fill_value, copy=False)

        # recreate
        data = SingleBlockManager(data, index, fastpath=True)
        generic.NDFrame.__init__(self, data)

        self._set_axis(0, index)
        self.name = name 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:series.py

示例4: sparse_reindex

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def sparse_reindex(self, new_index):
        """
        Conform sparse values to new SparseIndex

        Parameters
        ----------
        new_index : {BlockIndex, IntIndex}

        Returns
        -------
        reindexed : SparseSeries
        """
        if not isinstance(new_index, splib.SparseIndex):
            raise TypeError('new index must be a SparseIndex')

        block = self.block.sparse_reindex(new_index)
        new_data = SingleBlockManager(block, block.ref_items)
        return self._constructor(new_data, index=self.index,
                                 sparse_index=new_index,
                                 fill_value=self.fill_value).__finalize__(self) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:series.py

示例5: test_custom_repr

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def test_custom_repr():
    values = np.arange(3, dtype='int64')

    # series
    block = CustomBlock(values, placement=slice(0, 3))

    s = pd.Series(SingleBlockManager(block, pd.RangeIndex(3)))
    assert repr(s) == '0    Val: 0\n1    Val: 1\n2    Val: 2\ndtype: int64'

    # dataframe
    block = CustomBlock(values, placement=slice(0, 1))
    blk_mgr = BlockManager([block], [['col'], range(3)])
    df = pd.DataFrame(blk_mgr)
    assert repr(df) == '      col\n0  Val: 0\n1  Val: 1\n2  Val: 2' 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_external_block.py

示例6: create_single_mgr

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def create_single_mgr(typestr, num_rows=None):
    if num_rows is None:
        num_rows = N

    return SingleBlockManager(
        create_block(typestr, placement=slice(0, num_rows), item_shape=()),
        np.arange(num_rows)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_internals.py

示例7: __init__

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def __init__(self, data=None, index=None, sparse_index=None, kind='block',
                 fill_value=None, name=None, dtype=None, copy=False,
                 fastpath=False):
        # TODO: Most of this should be refactored and shared with Series
        # 1. BlockManager -> array
        # 2. Series.index, Series.name, index, name reconciliation
        # 3. Implicit reindexing
        # 4. Implicit broadcasting
        # 5. Dict construction
        if data is None:
            data = []
        elif isinstance(data, SingleBlockManager):
            index = data.index
            data = data.blocks[0].values
        elif isinstance(data, (ABCSeries, ABCSparseSeries)):
            index = data.index if index is None else index
            dtype = data.dtype if dtype is None else dtype
            name = data.name if name is None else name

            if index is not None:
                data = data.reindex(index)

        elif isinstance(data, compat.Mapping):
            data, index = Series()._init_dict(data, index=index)

        elif is_scalar(data) and index is not None:
            data = np.full(len(index), fill_value=data)

        super(SparseSeries, self).__init__(
            SparseArray(data,
                        sparse_index=sparse_index,
                        kind=kind,
                        dtype=dtype,
                        fill_value=fill_value,
                        copy=copy),
            index=index, name=name,
            copy=False, fastpath=fastpath
        ) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:40,代码来源:series.py

示例8: _set_value

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _set_value(self, label, value, takeable=False):
        values = self.to_dense()

        # if the label doesn't exist, we will create a new object here
        # and possibly change the index
        new_values = values._set_value(label, value, takeable=takeable)
        if new_values is not None:
            values = new_values
        new_index = values.index
        values = SparseArray(values, fill_value=self.fill_value,
                             kind=self.kind)
        self._data = SingleBlockManager(values, new_index)
        self._index = new_index 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:series.py

示例9: _unpickle_series_compat

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _unpickle_series_compat(self, state):
        if isinstance(state, dict):
            self._data = state['_data']
            self.name = state['name']
            self.index = self._data.index

        elif isinstance(state, tuple):

            # < 0.12 series pickle

            nd_state, own_state = state

            # recreate the ndarray
            data = np.empty(nd_state[1], dtype=nd_state[2])
            np.ndarray.__setstate__(data, nd_state)

            # backwards compat
            index, name = own_state[0], None
            if len(own_state) > 1:
                name = own_state[1]

            # recreate
            self._data = SingleBlockManager(data, index, fastpath=True)
            self._index = index
            self.name = name

        else:
            raise Exception("cannot unpickle legacy formats -> [%s]" % state)

    # indexers 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:32,代码来源:series.py

示例10: _set_values

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _set_values(self, key, value):

        # this might be inefficient as we have to recreate the sparse array
        # rather than setting individual elements, but have to convert
        # the passed slice/boolean that's in dense space into a sparse indexer
        # not sure how to do that!
        if isinstance(key, Series):
            key = key.values

        values = self.values.to_dense()
        values[key] = libindex.convert_scalar(values, value)
        values = SparseArray(values, fill_value=self.fill_value,
                             kind=self.kind)
        self._data = SingleBlockManager(values, self.index) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:16,代码来源:series.py

示例11: set_value

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def set_value(self, label, value):
        """
        Quickly set single value at passed label. If label is not contained, a
        new object is created with the label placed at the end of the result
        index

        Parameters
        ----------
        label : object
            Partial indexing with MultiIndex not allowed
        value : object
            Scalar value

        Notes
        -----
        This method *always* returns a new object. It is not particularly
        efficient but is provided for API compatibility with Series

        Returns
        -------
        series : SparseSeries
        """
        values = self.to_dense()

        # if the label doesn't exist, we will create a new object here
        # and possibily change the index
        new_values = values.set_value(label, value)
        if new_values is not None:
            values = new_values
        new_index = values.index
        values = SparseArray(
            values, fill_value=self.fill_value, kind=self.kind)
        self._data = SingleBlockManager(values, new_index)
        self._index = new_index 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:36,代码来源:series.py

示例12: _set_values

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _set_values(self, key, value):

        # this might be inefficient as we have to recreate the sparse array
        # rather than setting individual elements, but have to convert
        # the passed slice/boolean that's in dense space into a sparse indexer
        # not sure how to do that!
        if isinstance(key, Series):
            key = key.values

        values = self.values.to_dense()
        values[key] = _index.convert_scalar(values, value)
        values = SparseArray(
            values, fill_value=self.fill_value, kind=self.kind)
        self._data = SingleBlockManager(values, self.index) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:series.py

示例13: _unpickle_series_compat

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _unpickle_series_compat(self, state):
        if isinstance(state, dict):
            self._data = state['_data']
            self.name = state['name']
            self.index = self._data.index

        elif isinstance(state, tuple):

            # < 0.12 series pickle

            nd_state, own_state = state

            # recreate the ndarray
            data = np.empty(nd_state[1], dtype=nd_state[2])
            np.ndarray.__setstate__(data, nd_state)

            # backwards compat
            index, name = own_state[0], None
            if len(own_state) > 1:
                name = own_state[1]
            index = _handle_legacy_indexes([index])[0]

            # recreate
            self._data = SingleBlockManager(data, index, fastpath=True)
            self.index = index
            self.name = name

        else:
            raise Exception("cannot unpickle legacy formats -> [%s]" % state)

    # indexers 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:33,代码来源:series.py

示例14: _set_value

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _set_value(self, label, value, takeable=False):
        values = self.to_dense()

        # if the label doesn't exist, we will create a new object here
        # and possibily change the index
        new_values = values._set_value(label, value, takeable=takeable)
        if new_values is not None:
            values = new_values
        new_index = values.index
        values = SparseArray(values, fill_value=self.fill_value,
                             kind=self.kind)
        self._data = SingleBlockManager(values, new_index)
        self._index = new_index 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:15,代码来源:series.py

示例15: _set_values

# 需要导入模块: from pandas.core import internals [as 别名]
# 或者: from pandas.core.internals import SingleBlockManager [as 别名]
def _set_values(self, key, value):

        # this might be inefficient as we have to recreate the sparse array
        # rather than setting individual elements, but have to convert
        # the passed slice/boolean that's in dense space into a sparse indexer
        # not sure how to do that!
        if isinstance(key, Series):
            key = key.values

        values = self.values.to_dense()
        values[key] = _index.convert_scalar(values, value)
        values = SparseArray(values, fill_value=self.fill_value,
                             kind=self.kind)
        self._data = SingleBlockManager(values, self.index) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:16,代码来源:series.py


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