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


Python common.isna方法代码示例

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


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

示例1: test_where_bug_transposition

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_where_bug_transposition(self):
        # see gh-7506
        a = DataFrame({0: [1, 2], 1: [3, 4], 2: [5, 6]})
        b = DataFrame({0: [np.nan, 8], 1: [9, np.nan], 2: [np.nan, np.nan]})
        do_not_replace = b.isna() | (a > b)

        expected = a.copy()
        expected[~do_not_replace] = b

        result = a.where(do_not_replace, b)
        assert_frame_equal(result, expected)

        a = DataFrame({0: [4, 6], 1: [1, 0]})
        b = DataFrame({0: [np.nan, 3], 1: [3, np.nan]})
        do_not_replace = b.isna() | (a > b)

        expected = a.copy()
        expected[~do_not_replace] = b

        result = a.where(do_not_replace, b)
        assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_indexing.py

示例2: test_where_none

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_where_none(self):
        # GH 4667
        # setting with None changes dtype
        df = DataFrame({'series': Series(range(10))}).astype(float)
        df[df > 7] = None
        expected = DataFrame(
            {'series': Series([0, 1, 2, 3, 4, 5, 6, 7, np.nan, np.nan])})
        assert_frame_equal(df, expected)

        # GH 7656
        df = DataFrame([{'A': 1, 'B': np.nan, 'C': 'Test'}, {
                       'A': np.nan, 'B': 'Test', 'C': np.nan}])
        msg = 'boolean setting on mixed-type'

        with pytest.raises(TypeError, match=msg):
            df.where(~isna(df), None, inplace=True) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_indexing.py

示例3: test_operators_none_as_na

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_operators_none_as_na(self, op):
        df = DataFrame({"col1": [2, 5.0, 123, None],
                        "col2": [1, 2, 3, 4]}, dtype=object)

        # since filling converts dtypes from object, changed expected to be
        # object
        filled = df.fillna(np.nan)
        result = op(df, 3)
        expected = op(filled, 3).astype(object)
        expected[com.isna(expected)] = None
        assert_frame_equal(result, expected)

        result = op(df, df)
        expected = op(filled, filled).astype(object)
        expected[com.isna(expected)] = None
        assert_frame_equal(result, expected)

        result = op(df, df.fillna(7))
        assert_frame_equal(result, expected)

        result = op(df.fillna(7), df)
        assert_frame_equal(result, expected, check_dtype=False) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_operators.py

示例4: test_combine_generic

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_combine_generic(self):
        df1 = self.frame
        df2 = self.frame.loc[self.frame.index[:-5], ['A', 'B', 'C']]

        combined = df1.combine(df2, np.add)
        combined2 = df2.combine(df1, np.add)
        assert combined['D'].isna().all()
        assert combined2['D'].isna().all()

        chunk = combined.loc[combined.index[:-5], ['A', 'B', 'C']]
        chunk2 = combined2.loc[combined2.index[:-5], ['A', 'B', 'C']]

        exp = self.frame.loc[self.frame.index[:-5],
                             ['A', 'B', 'C']].reindex_like(chunk) * 2
        assert_frame_equal(chunk, exp)
        assert_frame_equal(chunk2, exp) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_operators.py

示例5: test_where_none

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_where_none(self):
        # GH 4667
        # setting with None changes dtype
        df = DataFrame({'series': Series(range(10))}).astype(float)
        df[df > 7] = None
        expected = DataFrame(
            {'series': Series([0, 1, 2, 3, 4, 5, 6, 7, np.nan, np.nan])})
        assert_frame_equal(df, expected)

        # GH 7656
        df = DataFrame([{'A': 1, 'B': np.nan, 'C': 'Test'}, {
                       'A': np.nan, 'B': 'Test', 'C': np.nan}])
        expected = df.where(~isna(df), None)
        with tm.assert_raises_regex(TypeError, 'boolean setting '
                                    'on mixed-type'):
            df.where(~isna(df), None, inplace=True) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_indexing.py

示例6: test_operators_none_as_na

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_operators_none_as_na(self):
        df = DataFrame({"col1": [2, 5.0, 123, None],
                        "col2": [1, 2, 3, 4]}, dtype=object)

        ops = [operator.add, operator.sub, operator.mul, operator.truediv]

        # since filling converts dtypes from object, changed expected to be
        # object
        for op in ops:
            filled = df.fillna(np.nan)
            result = op(df, 3)
            expected = op(filled, 3).astype(object)
            expected[com.isna(expected)] = None
            assert_frame_equal(result, expected)

            result = op(df, df)
            expected = op(filled, filled).astype(object)
            expected[com.isna(expected)] = None
            assert_frame_equal(result, expected)

            result = op(df, df.fillna(7))
            assert_frame_equal(result, expected)

            result = op(df.fillna(7), df)
            assert_frame_equal(result, expected, check_dtype=False) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:test_operators.py

示例7: test_getitem_boolean_casting

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

        # don't upcast if we don't need to
        df = self.tsframe.copy()
        df['E'] = 1
        df['E'] = df['E'].astype('int32')
        df['E1'] = df['E'].copy()
        df['F'] = 1
        df['F'] = df['F'].astype('int64')
        df['F1'] = df['F'].copy()

        casted = df[df > 0]
        result = casted.get_dtype_counts()
        expected = Series({'float64': 4, 'int32': 2, 'int64': 2})
        assert_series_equal(result, expected)

        # int block splitting
        df.loc[df.index[1:3], ['E1', 'F1']] = 0
        casted = df[df > 0]
        result = casted.get_dtype_counts()
        expected = Series({'float64': 6, 'int32': 1, 'int64': 1})
        assert_series_equal(result, expected)

        # where dtype conversions
        # GH 3733
        df = DataFrame(data=np.random.randn(100, 50))
        df = df.where(df > 0)  # create nans
        bools = df > 0
        mask = isna(df)
        expected = bools.astype(float).mask(mask)
        result = bools.mask(mask)
        assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:34,代码来源:test_indexing.py

示例8: test_setitem_empty

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_setitem_empty(self):
        # GH 9596
        df = pd.DataFrame({'a': ['1', '2', '3'],
                           'b': ['11', '22', '33'],
                           'c': ['111', '222', '333']})

        result = df.copy()
        result.loc[result.b.isna(), 'a'] = result.a
        assert_frame_equal(result, df) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_indexing.py

示例9: test_getitem_fancy_slice_integers_step

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_getitem_fancy_slice_integers_step(self):
        df = DataFrame(np.random.randn(10, 5))

        # this is OK
        result = df.iloc[:8:2]  # noqa
        df.iloc[:8:2] = np.nan
        assert isna(df.iloc[:8:2]).values.all() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_indexing.py

示例10: test_setitem_fancy_mixed_2d

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

        with catch_warnings(record=True):
            simplefilter("ignore", DeprecationWarning)
            self.mixed_frame.ix[:5, ['C', 'B', 'A']] = 5
            result = self.mixed_frame.ix[:5, ['C', 'B', 'A']]
            assert (result.values == 5).all()

            self.mixed_frame.ix[5] = np.nan
            assert isna(self.mixed_frame.ix[5]).all()

            self.mixed_frame.ix[5] = self.mixed_frame.ix[6]
            assert_series_equal(self.mixed_frame.ix[5], self.mixed_frame.ix[6],
                                check_names=False)

        # #1432
        with catch_warnings(record=True):
            simplefilter("ignore", DeprecationWarning)
            df = DataFrame({1: [1., 2., 3.],
                            2: [3, 4, 5]})
            assert df._is_mixed_type

            df.ix[1] = [5, 10]

            expected = DataFrame({1: [1., 5., 3.],
                                  2: [3, 10, 5]})

            assert_frame_equal(df, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:30,代码来源:test_indexing.py

示例11: test_setitem_single_column_mixed_datetime

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_setitem_single_column_mixed_datetime(self):
        df = DataFrame(np.random.randn(5, 3), index=['a', 'b', 'c', 'd', 'e'],
                       columns=['foo', 'bar', 'baz'])

        df['timestamp'] = Timestamp('20010102')

        # check our dtypes
        result = df.get_dtype_counts()
        expected = Series({'float64': 3, 'datetime64[ns]': 1})
        assert_series_equal(result, expected)

        # set an allowable datetime64 type
        df.loc['b', 'timestamp'] = iNaT
        assert isna(df.loc['b', 'timestamp'])

        # allow this syntax
        df.loc['c', 'timestamp'] = np.nan
        assert isna(df.loc['c', 'timestamp'])

        # allow this syntax
        df.loc['d', :] = np.nan
        assert not isna(df.loc['c', :]).all()

        # as of GH 3216 this will now work!
        # try to set with a list like item
        # pytest.raises(
        #    Exception, df.loc.__setitem__, ('d', 'timestamp'), [np.nan]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:29,代码来源:test_indexing.py

示例12: test_reindex_frame_add_nat

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_reindex_frame_add_nat(self):
        rng = date_range('1/1/2000 00:00:00', periods=10, freq='10s')
        df = DataFrame({'A': np.random.randn(len(rng)), 'B': rng})

        result = df.reindex(lrange(15))
        assert np.issubdtype(result['B'].dtype, np.dtype('M8[ns]'))

        mask = com.isna(result)['B']
        assert mask[-5:].all()
        assert not mask[:-5].any() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_indexing.py

示例13: test_setitem_fancy_mixed_2d

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

        with catch_warnings(record=True):
            self.mixed_frame.ix[:5, ['C', 'B', 'A']] = 5
            result = self.mixed_frame.ix[:5, ['C', 'B', 'A']]
            assert (result.values == 5).all()

            self.mixed_frame.ix[5] = np.nan
            assert isna(self.mixed_frame.ix[5]).all()

            self.mixed_frame.ix[5] = self.mixed_frame.ix[6]
            assert_series_equal(self.mixed_frame.ix[5], self.mixed_frame.ix[6],
                                check_names=False)

        # #1432
        with catch_warnings(record=True):
            df = DataFrame({1: [1., 2., 3.],
                            2: [3, 4, 5]})
            assert df._is_mixed_type

            df.ix[1] = [5, 10]

            expected = DataFrame({1: [1., 5., 3.],
                                  2: [3, 10, 5]})

            assert_frame_equal(df, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:28,代码来源:test_indexing.py

示例14: test_setitem_single_column_mixed_datetime

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import isna [as 别名]
def test_setitem_single_column_mixed_datetime(self):
        df = DataFrame(randn(5, 3), index=['a', 'b', 'c', 'd', 'e'],
                       columns=['foo', 'bar', 'baz'])

        df['timestamp'] = Timestamp('20010102')

        # check our dtypes
        result = df.get_dtype_counts()
        expected = Series({'float64': 3, 'datetime64[ns]': 1})
        assert_series_equal(result, expected)

        # set an allowable datetime64 type
        df.loc['b', 'timestamp'] = iNaT
        assert isna(df.loc['b', 'timestamp'])

        # allow this syntax
        df.loc['c', 'timestamp'] = nan
        assert isna(df.loc['c', 'timestamp'])

        # allow this syntax
        df.loc['d', :] = nan
        assert not isna(df.loc['c', :]).all()

        # as of GH 3216 this will now work!
        # try to set with a list like item
        # pytest.raises(
        #    Exception, df.loc.__setitem__, ('d', 'timestamp'), [nan]) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:29,代码来源:test_indexing.py


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