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


Python common.is_integer_dtype方法代码示例

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


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

示例1: test_returned_dtype

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

        dtypes = [np.int16, np.int32, np.int64, np.float32, np.float64]
        if hasattr(np, 'float128'):
            dtypes.append(np.float128)

        for dtype in dtypes:
            s = Series(range(10), dtype=dtype)
            group_a = ['mean', 'std', 'var', 'skew', 'kurt']
            group_b = ['min', 'max']
            for method in group_a + group_b:
                result = getattr(s, method)()
                if is_integer_dtype(dtype) and method in group_a:
                    assert result.dtype == np.float64
                else:
                    assert result.dtype == dtype 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_nanops.py

示例2: test_delevel_infer_dtype

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_integer_dtype [as 别名]
def test_delevel_infer_dtype(self):
        tuples = [tuple
                  for tuple in cart_product(
                      ['foo', 'bar'], [10, 20], [1.0, 1.1])]
        index = MultiIndex.from_tuples(tuples, names=['prm0', 'prm1', 'prm2'])
        df = DataFrame(np.random.randn(8, 3), columns=['A', 'B', 'C'],
                       index=index)
        deleveled = df.reset_index()
        assert is_integer_dtype(deleveled['prm1'])
        assert is_float_dtype(deleveled['prm2']) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_multilevel.py

示例3: test_setitem_dtype_upcast

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

        # GH3216
        df = DataFrame([{"a": 1}, {"a": 3, "b": 2}])
        df['c'] = np.nan
        assert df['c'].dtype == np.float64

        df.loc[0, 'c'] = 'foo'
        expected = DataFrame([{"a": 1, "c": 'foo'},
                              {"a": 3, "b": 2, "c": np.nan}])
        tm.assert_frame_equal(df, expected)

        # GH10280
        df = DataFrame(np.arange(6, dtype='int64').reshape(2, 3),
                       index=list('ab'),
                       columns=['foo', 'bar', 'baz'])

        for val in [3.14, 'wxyz']:
            left = df.copy()
            left.loc['a', 'bar'] = val
            right = DataFrame([[0, val, 2], [3, 4, 5]], index=list('ab'),
                              columns=['foo', 'bar', 'baz'])

            tm.assert_frame_equal(left, right)
            assert is_integer_dtype(left['foo'])
            assert is_integer_dtype(left['baz'])

        left = DataFrame(np.arange(6, dtype='int64').reshape(2, 3) / 10.0,
                         index=list('ab'),
                         columns=['foo', 'bar', 'baz'])
        left.loc['a', 'bar'] = 'wxyz'

        right = DataFrame([[0, 'wxyz', .2], [.3, .4, .5]], index=list('ab'),
                          columns=['foo', 'bar', 'baz'])

        tm.assert_frame_equal(left, right)
        assert is_float_dtype(left['foo'])
        assert is_float_dtype(left['baz']) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:40,代码来源:test_indexing.py

示例4: test_constructor_list_of_lists

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_integer_dtype [as 别名]
def test_constructor_list_of_lists(self):
        # GH #484
        df = DataFrame(data=[[1, 'a'], [2, 'b']], columns=["num", "str"])
        assert is_integer_dtype(df['num'])
        assert df['str'].dtype == np.object_

        # GH 4851
        # list of 0-dim ndarrays
        expected = DataFrame({0: np.arange(10)})
        data = [np.array(x) for x in range(10)]
        result = DataFrame(data)
        tm.assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_constructors.py

示例5: test_is_not_integer_dtype

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_integer_dtype [as 别名]
def test_is_not_integer_dtype(dtype):
    assert not com.is_integer_dtype(dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:test_common.py

示例6: test_is_signed_integer_dtype

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_integer_dtype [as 别名]
def test_is_signed_integer_dtype(dtype):
    assert com.is_integer_dtype(dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:test_common.py

示例7: test_constructor_list_of_lists

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_integer_dtype [as 别名]
def test_constructor_list_of_lists(self):
        # GH #484
        l = [[1, 'a'], [2, 'b']]
        df = DataFrame(data=l, columns=["num", "str"])
        assert is_integer_dtype(df['num'])
        assert df['str'].dtype == np.object_

        # GH 4851
        # list of 0-dim ndarrays
        expected = DataFrame({0: np.arange(10)})
        data = [np.array(x) for x in range(10)]
        result = DataFrame(data)
        tm.assert_frame_equal(result, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:15,代码来源:test_constructors.py

示例8: test_is_integer_dtype

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_integer_dtype [as 别名]
def test_is_integer_dtype():
    assert not com.is_integer_dtype(str)
    assert not com.is_integer_dtype(float)
    assert not com.is_integer_dtype(np.datetime64)
    assert not com.is_integer_dtype(np.timedelta64)
    assert not com.is_integer_dtype(pd.Index([1, 2.]))
    assert not com.is_integer_dtype(np.array(['a', 'b']))
    assert not com.is_integer_dtype(np.array([], dtype=np.timedelta64))

    assert com.is_integer_dtype(int)
    assert com.is_integer_dtype(np.uint64)
    assert com.is_integer_dtype(pd.Series([1, 2])) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:14,代码来源:test_common.py

示例9: test_basic_types

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_integer_dtype [as 别名]
def test_basic_types(self, sparse, dtype):
        # GH 10531
        s_list = list('abc')
        s_series = Series(s_list)
        s_df = DataFrame({'a': [0, 1, 0, 1, 2],
                          'b': ['A', 'A', 'B', 'C', 'C'],
                          'c': [2, 3, 3, 3, 2]})

        expected = DataFrame({'a': [1, 0, 0],
                              'b': [0, 1, 0],
                              'c': [0, 0, 1]},
                             dtype=self.effective_dtype(dtype),
                             columns=list('abc'))
        if sparse:
            if is_integer_dtype(dtype):
                fill_value = 0
            elif dtype == bool:
                fill_value = False
            else:
                fill_value = 0.0

            expected = expected.apply(SparseArray, fill_value=fill_value)
        result = get_dummies(s_list, sparse=sparse, dtype=dtype)
        tm.assert_frame_equal(result, expected)

        result = get_dummies(s_series, sparse=sparse, dtype=dtype)
        tm.assert_frame_equal(result, expected)

        result = get_dummies(s_df, columns=s_df.columns,
                             sparse=sparse, dtype=dtype)
        if sparse:
            dtype_name = 'Sparse[{}, {}]'.format(
                self.effective_dtype(dtype).name,
                fill_value
            )
        else:
            dtype_name = self.effective_dtype(dtype).name

        expected = Series({dtype_name: 8})
        tm.assert_series_equal(result.get_dtype_counts(), expected)

        result = get_dummies(s_df, columns=['a'], sparse=sparse, dtype=dtype)

        expected_counts = {'int64': 1, 'object': 1}
        expected_counts[dtype_name] = 3 + expected_counts.get(dtype_name, 0)

        expected = Series(expected_counts).sort_index()
        tm.assert_series_equal(result.get_dtype_counts().sort_index(),
                               expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:51,代码来源:test_reshape.py


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