當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。