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


Python NDFrame._set_item方法代码示例

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


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

示例1: __setitem__

# 需要导入模块: from pandas.core.generic import NDFrame [as 别名]
# 或者: from pandas.core.generic.NDFrame import _set_item [as 别名]
    def __setitem__(self, key, value):
        _, N, K = self.shape
        if isinstance(value, DataFrame):
            value = value.reindex(index=self.major_axis, columns=self.minor_axis)
            mat = value.values
        elif isinstance(value, np.ndarray):
            assert value.shape == (N, K)
            mat = np.asarray(value)
        elif np.isscalar(value):
            dtype = _infer_dtype(value)
            mat = np.empty((N, K), dtype=dtype)
            mat.fill(value)

        mat = mat.reshape((1, N, K))
        NDFrame._set_item(self, key, mat)
开发者ID:datakungfu,项目名称:pandas,代码行数:17,代码来源:panel.py

示例2: __setitem__

# 需要导入模块: from pandas.core.generic import NDFrame [as 别名]
# 或者: from pandas.core.generic.NDFrame import _set_item [as 别名]
    def __setitem__(self, key, value):
        _, N, K = self.shape
        if isinstance(value, DataFrame):
            value = value.reindex(index=self.major_axis, columns=self.minor_axis)
            mat = value.values
        elif isinstance(value, np.ndarray):
            if value.shape != (N, K):
                raise AssertionError(("Shape of values must be (%d, %d), " "not (%d, %d)") % ((N, K) + values.shape))
            mat = np.asarray(value)
        elif np.isscalar(value):
            dtype = _infer_dtype(value)
            mat = np.empty((N, K), dtype=dtype)
            mat.fill(value)
        else:
            raise TypeError("Cannot set item of type: %s" % str(type(value)))

        mat = mat.reshape((1, N, K))
        NDFrame._set_item(self, key, mat)
开发者ID:ricarpor,项目名称:pandas,代码行数:20,代码来源:panel.py

示例3: __setitem__

# 需要导入模块: from pandas.core.generic import NDFrame [as 别名]
# 或者: from pandas.core.generic.NDFrame import _set_item [as 别名]
    def __setitem__(self, key, value):
        shape = tuple(self.shape)
        if isinstance(value, self._constructor_sliced):
            value = value.reindex(
                **self._construct_axes_dict_for_slice(self._AXIS_ORDERS[1:]))
            mat = value.values
        elif isinstance(value, np.ndarray):
            if not ((value.shape == shape[1:])):
                raise AssertionError()
            mat = np.asarray(value)
        elif np.isscalar(value):
            dtype, value = _infer_dtype_from_scalar(value)
            mat = np.empty(shape[1:], dtype=dtype)
            mat.fill(value)
        else:
            raise TypeError('Cannot set item of type: %s' % str(type(value)))

        mat = mat.reshape(tuple([1]) + shape[1:])
        NDFrame._set_item(self, key, mat)
开发者ID:APWaldo,项目名称:pandas,代码行数:21,代码来源:panel.py

示例4: __setitem__

# 需要导入模块: from pandas.core.generic import NDFrame [as 别名]
# 或者: from pandas.core.generic.NDFrame import _set_item [as 别名]
    def __setitem__(self, key, value):
        shape = tuple(self.shape)
        if isinstance(value, self._constructor_sliced):
            value = value.reindex(**self._construct_axes_dict_for_slice(self._AXIS_ORDERS[1:]))
            mat = value.values
        elif isinstance(value, np.ndarray):
            if value.shape != shape[1:]:
                raise ValueError(
                    "shape of value must be {0}, shape of given " "object was {1}".format(shape[1:], value.shape)
                )
            mat = np.asarray(value)
        elif np.isscalar(value):
            dtype, value = _infer_dtype_from_scalar(value)
            mat = np.empty(shape[1:], dtype=dtype)
            mat.fill(value)
        else:
            raise TypeError("Cannot set item of type: %s" % str(type(value)))

        mat = mat.reshape(tuple([1]) + shape[1:])
        NDFrame._set_item(self, key, mat)
开发者ID:ErwcPKerr,项目名称:pandas,代码行数:22,代码来源:panel.py

示例5: __setitem__

# 需要导入模块: from pandas.core.generic import NDFrame [as 别名]
# 或者: from pandas.core.generic.NDFrame import _set_item [as 别名]
    def __setitem__(self, key, value):
        _, N, K = self.shape

        # XXX
        if isinstance(value, LongPanel):
            if len(value.items) != 1:
                raise ValueError('Input panel must have only one item!')

            value = value.to_wide()[value.items[0]]

        if isinstance(value, DataFrame):
            value = value.reindex(index=self.major_axis,
                                  columns=self.minor_axis)
            mat = value.values
        elif isinstance(value, np.ndarray):
            assert(value.shape == (N, K))
            mat = np.asarray(value)
        elif np.isscalar(value):
            dtype = _infer_dtype(value)
            mat = np.empty((N, K), dtype=dtype)
            mat.fill(value)

        mat = mat.reshape((1, N, K))
        NDFrame._set_item(self, key, mat)
开发者ID:bshanks,项目名称:pandas,代码行数:26,代码来源:panel.py


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