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


Python common.standardize_mapping方法代码示例

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


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

示例1: test_standardize_mapping

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import standardize_mapping [as 别名]
def test_standardize_mapping():
    # No uninitialized defaultdicts
    with pytest.raises(TypeError):
        com.standardize_mapping(collections.defaultdict)

    # No non-mapping subtypes, instance
    with pytest.raises(TypeError):
        com.standardize_mapping([])

    # No non-mapping subtypes, class
    with pytest.raises(TypeError):
        com.standardize_mapping(list)

    fill = {'bad': 'data'}
    assert (com.standardize_mapping(fill) == dict)

    # Convert instance to type
    assert (com.standardize_mapping({}) == dict)

    dd = collections.defaultdict(list)
    assert isinstance(com.standardize_mapping(dd), partial) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_common.py

示例2: to_dict

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import standardize_mapping [as 别名]
def to_dict(self, into=dict):
        """
        Convert Series to {label -> value} dict or dict-like object.

        Parameters
        ----------
        into : class, default dict
            The collections.Mapping subclass to use as the return
            object. Can be the actual class or an empty
            instance of the mapping type you want.  If you want a
            collections.defaultdict, you must pass it initialized.

            .. versionadded:: 0.21.0

        Returns
        -------
        value_dict : collections.Mapping

        Examples
        --------
        >>> s = pd.Series([1, 2, 3, 4])
        >>> s.to_dict()
        {0: 1, 1: 2, 2: 3, 3: 4}
        >>> from collections import OrderedDict, defaultdict
        >>> s.to_dict(OrderedDict)
        OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
        >>> dd = defaultdict(list)
        >>> s.to_dict(dd)
        defaultdict(<type 'list'>, {0: 1, 1: 2, 2: 3, 3: 4})
        """
        # GH16122
        into_c = com.standardize_mapping(into)
        return into_c(compat.iteritems(self)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:35,代码来源:series.py


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