本文整理汇总了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)
示例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))