当前位置: 首页>>代码示例>>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;未经允许,请勿转载。