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


Python common.is_object_dtype方法代码示例

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


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

示例1: test_different

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_object_dtype [as 别名]
def test_different(self, right_vals):

        left = DataFrame({'A': ['foo', 'bar'],
                          'B': Series(['foo', 'bar']).astype('category'),
                          'C': [1, 2],
                          'D': [1.0, 2.0],
                          'E': Series([1, 2], dtype='uint64'),
                          'F': Series([1, 2], dtype='int32')})
        right = DataFrame({'A': right_vals})

        # GH 9780
        # We allow merging on object and categorical cols and cast
        # categorical cols to object
        result = pd.merge(left, right, on='A')
        assert is_object_dtype(result.A.dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_merge.py

示例2: test_merge_incompat_dtypes_are_ok

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_object_dtype [as 别名]
def test_merge_incompat_dtypes_are_ok(self, df1_vals, df2_vals):
        # these are explicity allowed incompat merges, that pass thru
        # the result type is dependent on if the values on the rhs are
        # inferred, otherwise these will be coereced to object

        df1 = DataFrame({'A': df1_vals})
        df2 = DataFrame({'A': df2_vals})

        result = pd.merge(df1, df2, on=['A'])
        assert is_object_dtype(result.A.dtype)
        result = pd.merge(df2, df1, on=['A'])
        assert is_object_dtype(result.A.dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_merge.py

示例3: test_is_object

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_object_dtype [as 别名]
def test_is_object():
    assert com.is_object_dtype(object)
    assert com.is_object_dtype(np.array([], dtype=object))

    assert not com.is_object_dtype(int)
    assert not com.is_object_dtype(np.array([], dtype=int))
    assert not com.is_object_dtype([1, 2, 3]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_common.py

示例4: _is_numeric

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_object_dtype [as 别名]
def _is_numeric(self):
        from pandas.core.dtypes.common import is_object_dtype
        return not is_object_dtype(self.subtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:sparse.py

示例5: test_different

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_object_dtype [as 别名]
def test_different(self, right_vals):

        left = DataFrame({'A': ['foo', 'bar'],
                          'B': Series(['foo', 'bar']).astype('category'),
                          'C': [1, 2],
                          'D': [1.0, 2.0],
                          'E': Series([1, 2], dtype='uint64'),
                          'F': Series([1, 2], dtype='int32')})
        right = DataFrame({'A': right_vals})

        # GH 9780
        # We allow merging on object and categorical cols and cast
        # categorical cols to object
        if (is_categorical_dtype(right['A'].dtype) or
                is_object_dtype(right['A'].dtype)):
            result = pd.merge(left, right, on='A')
            assert is_object_dtype(result.A.dtype)

        # GH 9780
        # We raise for merging on object col and int/float col and
        # merging on categorical col and int/float col
        else:
            msg = ("You are trying to merge on "
                   "{lk_dtype} and {rk_dtype} columns. "
                   "If you wish to proceed you should use "
                   "pd.concat".format(lk_dtype=left['A'].dtype,
                                      rk_dtype=right['A'].dtype))
            with tm.assert_raises_regex(ValueError, msg):
                pd.merge(left, right, on='A') 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:31,代码来源:test_merge.py

示例6: test_different

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_object_dtype [as 别名]
def test_different(self, df):

        # we expect differences by kind
        # to be ok, while other differences should return object

        left = df
        for col in df.columns:
            right = DataFrame({'A': df[col]})
            result = pd.merge(left, right, on='A')
            assert is_object_dtype(result.A.dtype) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:12,代码来源:test_merge.py

示例7: make_sparse

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_object_dtype [as 别名]
def make_sparse(arr, kind='block', fill_value=None, dtype=None, copy=False):
    """
    Convert ndarray to sparse format

    Parameters
    ----------
    arr : ndarray
    kind : {'block', 'integer'}
    fill_value : NaN or another value
    dtype : np.dtype, optional
    copy : bool, default False

    Returns
    -------
    (sparse_values, index, fill_value) : (ndarray, SparseIndex, Scalar)
    """

    arr = _sanitize_values(arr)

    if arr.ndim > 1:
        raise TypeError("expected dimension <= 1 data")

    if fill_value is None:
        fill_value = na_value_for_dtype(arr.dtype)

    if isna(fill_value):
        mask = notna(arr)
    else:
        # For str arrays in NumPy 1.12.0, operator!= below isn't
        # element-wise but just returns False if fill_value is not str,
        # so cast to object comparison to be safe
        if is_string_dtype(arr):
            arr = arr.astype(object)

        if is_object_dtype(arr.dtype):
            # element-wise equality check method in numpy doesn't treat
            # each element type, eg. 0, 0.0, and False are treated as
            # same. So we have to check the both of its type and value.
            mask = splib.make_mask_object_ndarray(arr, fill_value)
        else:
            mask = arr != fill_value

    length = len(arr)
    if length != len(mask):
        # the arr is a SparseArray
        indices = mask.sp_index.indices
    else:
        indices = mask.nonzero()[0].astype(np.int32)

    index = _make_index(length, indices, kind)
    sparsified_values = arr[mask]
    if dtype is not None:
        sparsified_values = astype_nansafe(sparsified_values, dtype=dtype)
    # TODO: copy
    return sparsified_values, index, fill_value 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:57,代码来源:sparse.py


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