當前位置: 首頁>>代碼示例>>Python>>正文


Python testing.add_nans方法代碼示例

本文整理匯總了Python中pandas.util.testing.add_nans方法的典型用法代碼示例。如果您正苦於以下問題:Python testing.add_nans方法的具體用法?Python testing.add_nans怎麽用?Python testing.add_nans使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.util.testing的用法示例。


在下文中一共展示了testing.add_nans方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_panel_join_overlap

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_panel_join_overlap(self):
        with catch_warnings(record=True):
            panel = tm.makePanel()
            tm.add_nans(panel)

            p1 = panel.loc[['ItemA', 'ItemB', 'ItemC']]
            p2 = panel.loc[['ItemB', 'ItemC']]

            # Expected index is
            #
            # ItemA, ItemB_p1, ItemC_p1, ItemB_p2, ItemC_p2
            joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2')
            p1_suf = p1.loc[['ItemB', 'ItemC']].add_suffix('_p1')
            p2_suf = p2.loc[['ItemB', 'ItemC']].add_suffix('_p2')
            no_overlap = panel.loc[['ItemA']]
            expected = no_overlap.join(p1_suf.join(p2_suf))
            tm.assert_panel_equal(joined, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_join.py

示例2: test_sparse_friendly

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_sparse_friendly(df):
    sdf = df[['C', 'D']].to_sparse()
    panel = tm.makePanel()
    tm.add_nans(panel)

    def _check_work(gp):
        gp.mean()
        gp.agg(np.mean)
        dict(iter(gp))

    # it works!
    _check_work(sdf.groupby(lambda x: x // 2))
    _check_work(sdf['C'].groupby(lambda x: x // 2))
    _check_work(sdf.groupby(df['A']))

    # do this someday
    # _check_work(panel.groupby(lambda x: x.month, axis=1)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_groupby.py

示例3: test_panel_groupby

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_panel_groupby():
    panel = tm.makePanel()
    tm.add_nans(panel)
    grouped = panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1},
                            axis='items')
    agged = grouped.mean()
    agged2 = grouped.agg(lambda x: x.mean('items'))

    tm.assert_panel_equal(agged, agged2)

    tm.assert_index_equal(agged.items, Index([0, 1]))

    grouped = panel.groupby(lambda x: x.month, axis='major')
    agged = grouped.mean()

    exp = Index(sorted(list(set(panel.major_axis.month))))
    tm.assert_index_equal(agged.major_axis, exp)

    grouped = panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1},
                            axis='minor')
    agged = grouped.mean()
    tm.assert_index_equal(agged.minor_axis, Index([0, 1])) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_groupby.py

示例4: test_sparse_friendly

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_sparse_friendly(df):
    sdf = df[['C', 'D']].to_sparse()
    with catch_warnings(record=True):
        panel = tm.makePanel()
        tm.add_nans(panel)

    def _check_work(gp):
        gp.mean()
        gp.agg(np.mean)
        dict(iter(gp))

    # it works!
    _check_work(sdf.groupby(lambda x: x // 2))
    _check_work(sdf['C'].groupby(lambda x: x // 2))
    _check_work(sdf.groupby(df['A']))

    # do this someday
    # _check_work(panel.groupby(lambda x: x.month, axis=1)) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:20,代碼來源:test_groupby.py

示例5: test_panel_groupby

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_panel_groupby():
    with catch_warnings(record=True):
        panel = tm.makePanel()
        tm.add_nans(panel)
        grouped = panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1},
                                axis='items')
        agged = grouped.mean()
        agged2 = grouped.agg(lambda x: x.mean('items'))

        tm.assert_panel_equal(agged, agged2)

        tm.assert_index_equal(agged.items, Index([0, 1]))

        grouped = panel.groupby(lambda x: x.month, axis='major')
        agged = grouped.mean()

        exp = Index(sorted(list(set(panel.major_axis.month))))
        tm.assert_index_equal(agged.major_axis, exp)

        grouped = panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1},
                                axis='minor')
        agged = grouped.mean()
        tm.assert_index_equal(agged.minor_axis, Index([0, 1])) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:test_groupby.py

示例6: test_panel_groupby

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_panel_groupby(self):
        with catch_warnings(record=True):
            self.panel = tm.makePanel()
            tm.add_nans(self.panel)
            grouped = self.panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1},
                                         axis='items')
            agged = grouped.mean()
            agged2 = grouped.agg(lambda x: x.mean('items'))

            tm.assert_panel_equal(agged, agged2)

            tm.assert_index_equal(agged.items, Index([0, 1]))

            grouped = self.panel.groupby(lambda x: x.month, axis='major')
            agged = grouped.mean()

            exp = Index(sorted(list(set(self.panel.major_axis.month))))
            tm.assert_index_equal(agged.major_axis, exp)

            grouped = self.panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1},
                                         axis='minor')
            agged = grouped.mean()
            tm.assert_index_equal(agged.minor_axis, Index([0, 1])) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:25,代碼來源:test_groupby.py

示例7: make_test_panel

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def make_test_panel():
    with catch_warnings(record=True):
        simplefilter("ignore", FutureWarning)
        _panel = tm.makePanel()
        tm.add_nans(_panel)
        _panel = _panel.copy()
    return _panel 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_panel.py

示例8: test_panel_join

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_panel_join(self):
        with catch_warnings(record=True):
            panel = tm.makePanel()
            tm.add_nans(panel)

            p1 = panel.iloc[:2, :10, :3]
            p2 = panel.iloc[2:, 5:, 2:]

            # left join
            result = p1.join(p2)
            expected = p1.copy()
            expected['ItemC'] = p2['ItemC']
            tm.assert_panel_equal(result, expected)

            # right join
            result = p1.join(p2, how='right')
            expected = p2.copy()
            expected['ItemA'] = p1['ItemA']
            expected['ItemB'] = p1['ItemB']
            expected = expected.reindex(items=['ItemA', 'ItemB', 'ItemC'])
            tm.assert_panel_equal(result, expected)

            # inner join
            result = p1.join(p2, how='inner')
            expected = panel.iloc[:, 5:10, 2:3]
            tm.assert_panel_equal(result, expected)

            # outer join
            result = p1.join(p2, how='outer')
            expected = p1.reindex(major=panel.major_axis,
                                  minor=panel.minor_axis)
            expected = expected.join(p2.reindex(major=panel.major_axis,
                                                minor=panel.minor_axis))
            tm.assert_panel_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:36,代碼來源:test_join.py

示例9: make_test_panel

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def make_test_panel():
    with catch_warnings(record=True):
        _panel = tm.makePanel()
        tm.add_nans(_panel)
        _panel = _panel.copy()
    return _panel 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:8,代碼來源:test_panel.py

示例10: test_panel_join

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_panel_join(self):
        panel = tm.makePanel()
        tm.add_nans(panel)

        p1 = panel.ix[:2, :10, :3]
        p2 = panel.ix[2:, 5:, 2:]

        # left join
        result = p1.join(p2)
        expected = p1.copy()
        expected['ItemC'] = p2['ItemC']
        tm.assert_panel_equal(result, expected)

        # right join
        result = p1.join(p2, how='right')
        expected = p2.copy()
        expected['ItemA'] = p1['ItemA']
        expected['ItemB'] = p1['ItemB']
        expected = expected.reindex(items=['ItemA', 'ItemB', 'ItemC'])
        tm.assert_panel_equal(result, expected)

        # inner join
        result = p1.join(p2, how='inner')
        expected = panel.ix[:, 5:10, 2:3]
        tm.assert_panel_equal(result, expected)

        # outer join
        result = p1.join(p2, how='outer')
        expected = p1.reindex(major=panel.major_axis,
                              minor=panel.minor_axis)
        expected = expected.join(p2.reindex(major=panel.major_axis,
                                            minor=panel.minor_axis))
        tm.assert_panel_equal(result, expected) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:35,代碼來源:test_merge.py

示例11: test_panel_join_overlap

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_panel_join_overlap(self):
        panel = tm.makePanel()
        tm.add_nans(panel)

        p1 = panel.ix[['ItemA', 'ItemB', 'ItemC']]
        p2 = panel.ix[['ItemB', 'ItemC']]

        joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2')
        p1_suf = p1.ix[['ItemB', 'ItemC']].add_suffix('_p1')
        p2_suf = p2.ix[['ItemB', 'ItemC']].add_suffix('_p2')
        no_overlap = panel.ix[['ItemA']]
        expected = p1_suf.join(p2_suf).join(no_overlap)
        tm.assert_panel_equal(joined, expected) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:15,代碼來源:test_merge.py

示例12: add_nans

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def add_nans(panel4d):
    for l, label in enumerate(panel4d.labels):
        panel = panel4d[label]
        tm.add_nans(panel) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:6,代碼來源:test_panel4d.py

示例13: setup_method

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def setup_method(self, method):
        with catch_warnings(record=True):
            self.panel4d = tm.makePanel4D(nper=8)
            add_nans(self.panel4d) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:6,代碼來源:test_panel4d.py

示例14: test_isna_isnull

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import add_nans [as 別名]
def test_isna_isnull(self, isna_f):
        assert not isna_f(1.)
        assert isna_f(None)
        assert isna_f(np.NaN)
        assert float('nan')
        assert not isna_f(np.inf)
        assert not isna_f(-np.inf)

        # series
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert isinstance(isna_f(s), Series)

        # frame
        for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
                   tm.makeMixedDataFrame()]:
            result = isna_f(df)
            expected = df.apply(isna_f)
            tm.assert_frame_equal(result, expected)

        # panel
        with catch_warnings(record=True):
            for p in [tm.makePanel(), tm.makePeriodPanel(),
                      tm.add_nans(tm.makePanel())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel_equal(result, expected)

        # panel 4d
        with catch_warnings(record=True):
            for p in [tm.makePanel4D(), tm.add_nans_panel4d(tm.makePanel4D())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel4d_equal(result, expected) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:37,代碼來源:test_missing.py


注:本文中的pandas.util.testing.add_nans方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。