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


Python compat.product方法代码示例

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


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

示例1: test_pivot_table_dropna

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_pivot_table_dropna(self):
        df = DataFrame({'amount': {0: 60000, 1: 100000, 2: 50000, 3: 30000},
                        'customer': {0: 'A', 1: 'A', 2: 'B', 3: 'C'},
                        'month': {0: 201307, 1: 201309, 2: 201308, 3: 201310},
                        'product': {0: 'a', 1: 'b', 2: 'c', 3: 'd'},
                        'quantity': {0: 2000000, 1: 500000,
                                     2: 1000000, 3: 1000000}})
        pv_col = df.pivot_table('quantity', 'month', [
                                'customer', 'product'], dropna=False)
        pv_ind = df.pivot_table(
            'quantity', ['customer', 'product'], 'month', dropna=False)

        m = MultiIndex.from_tuples([('A', 'a'), ('A', 'b'), ('A', 'c'),
                                    ('A', 'd'), ('B', 'a'), ('B', 'b'),
                                    ('B', 'c'), ('B', 'd'), ('C', 'a'),
                                    ('C', 'b'), ('C', 'c'), ('C', 'd')],
                                   names=['customer', 'product'])
        tm.assert_index_equal(pv_col.columns, m)
        tm.assert_index_equal(pv_ind.index, m) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_pivot.py

示例2: test_margins_dtype

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_margins_dtype(self):
        # GH 17013

        df = self.data.copy()
        df[['D', 'E', 'F']] = np.arange(len(df) * 3).reshape(len(df), 3)

        mi_val = list(product(['bar', 'foo'], ['one', 'two'])) + [('All', '')]
        mi = MultiIndex.from_tuples(mi_val, names=('A', 'B'))
        expected = DataFrame({'dull': [12, 21, 3, 9, 45],
                              'shiny': [33, 0, 36, 51, 120]},
                             index=mi).rename_axis('C', axis=1)
        expected['All'] = expected['dull'] + expected['shiny']

        result = df.pivot_table(values='D', index=['A', 'B'],
                                       columns='C', margins=True,
                                       aggfunc=np.sum, fill_value=0)

        tm.assert_frame_equal(expected, result) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_pivot.py

示例3: test_rank_tie_methods

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_rank_tie_methods(self):
        s = self.s

        def _check(s, expected, method='average'):
            result = s.rank(method=method)
            tm.assert_series_equal(result, Series(expected))

        dtypes = [None, object]
        disabled = {(object, 'first')}
        results = self.results

        for method, dtype in product(results, dtypes):
            if (dtype, method) in disabled:
                continue
            series = s if dtype is None else s.astype(dtype)
            _check(series, results[method], method=method) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_rank.py

示例4: test_rank_descending

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_rank_descending(self):
        dtypes = ['O', 'f8', 'i8']

        for dtype, method in product(dtypes, self.results):
            if 'i' in dtype:
                s = self.s.dropna()
            else:
                s = self.s.astype(dtype)

            res = s.rank(ascending=False)
            expected = (s.max() - s).rank()
            assert_series_equal(res, expected)

            if method == 'first' and dtype == 'O':
                continue

            expected = (s.max() - s).rank(method=method)
            res2 = s.rank(method=method, ascending=False)
            assert_series_equal(res2, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_rank.py

示例5: test_resample_group_info

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_resample_group_info(self):  # GH10914
        for n, k in product((10000, 100000), (10, 100, 1000)):
            dr = date_range(start='2015-08-27', periods=n // 10, freq='T')
            ts = Series(np.random.randint(0, n // k, n).astype('int64'),
                        index=np.random.choice(dr, n))

            left = ts.resample('30T').nunique()
            ix = date_range(start=ts.index.min(), end=ts.index.max(),
                            freq='30T')

            vals = ts.values
            bins = np.searchsorted(ix.values, ts.index, side='right')

            sorter = np.lexsort((vals, bins))
            vals, bins = vals[sorter], bins[sorter]

            mask = np.r_[True, vals[1:] != vals[:-1]]
            mask |= np.r_[True, bins[1:] != bins[:-1]]

            arr = np.bincount(bins[mask] - 1,
                              minlength=len(ix)).astype('int64', copy=False)
            right = Series(arr, index=ix)

            assert_series_equal(left, right) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:test_resample.py

示例6: test_rank_tie_methods

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_rank_tie_methods(self):
        s = self.s

        def _check(s, expected, method='average'):
            result = s.rank(method=method)
            tm.assert_series_equal(result, Series(expected))

        dtypes = [None, object]
        disabled = set([(object, 'first')])
        results = self.results

        for method, dtype in product(results, dtypes):
            if (dtype, method) in disabled:
                continue
            series = s if dtype is None else s.astype(dtype)
            _check(series, results[method], method=method) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_rank.py

示例7: test_rank_2d_tie_methods

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_rank_2d_tie_methods(self):
        df = self.df

        def _check2d(df, expected, method='average', axis=0):
            exp_df = DataFrame({'A': expected, 'B': expected})

            if axis == 1:
                df = df.T
                exp_df = exp_df.T

            result = df.rank(method=method, axis=axis)
            assert_frame_equal(result, exp_df)

        dtypes = [None, object]
        disabled = set([(object, 'first')])
        results = self.results

        for method, axis, dtype in product(results, [0, 1], dtypes):
            if (dtype, method) in disabled:
                continue
            frame = df if dtype is None else df.astype(dtype)
            _check2d(frame, results[method], method=method, axis=axis) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_rank.py

示例8: test_margins_dtype_len

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_margins_dtype_len(self):
        mi_val = list(product(['bar', 'foo'], ['one', 'two'])) + [('All', '')]
        mi = MultiIndex.from_tuples(mi_val, names=('A', 'B'))
        expected = DataFrame({'dull': [1, 1, 2, 1, 5],
                              'shiny': [2, 0, 2, 2, 6]},
                             index=mi).rename_axis('C', axis=1)
        expected['All'] = expected['dull'] + expected['shiny']

        result = self.data.pivot_table(values='D', index=['A', 'B'],
                                       columns='C', margins=True,
                                       aggfunc=len, fill_value=0)

        tm.assert_frame_equal(expected, result) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_pivot.py

示例9: test_pivot_integer_columns

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_pivot_integer_columns(self):
        # caused by upstream bug in unstack

        d = date.min
        data = list(product(['foo', 'bar'], ['A', 'B', 'C'], ['x1', 'x2'],
                            [d + timedelta(i)
                             for i in range(20)], [1.0]))
        df = DataFrame(data)
        table = df.pivot_table(values=4, index=[0, 1, 3], columns=[2])

        df2 = df.rename(columns=str)
        table2 = df2.pivot_table(
            values='4', index=['0', '1', '3'], columns=['2'])

        tm.assert_frame_equal(table, table2, check_names=False) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_pivot.py

示例10: test_xs_integer_key

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_xs_integer_key():
    # see gh-2107
    dates = lrange(20111201, 20111205)
    ids = 'abcde'
    index = MultiIndex.from_tuples(
        [x for x in cart_product(dates, ids)],
        names=['date', 'secid'])
    df = DataFrame(
        np.random.randn(len(index), 3), index, ['X', 'Y', 'Z'])

    result = df.xs(20111201, level='date')
    expected = df.loc[20111201, :]
    tm.assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_xs.py

示例11: test_size

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_size(df):
    grouped = df.groupby(['A', 'B'])
    result = grouped.size()
    for key, group in grouped:
        assert result[key] == len(group)

    grouped = df.groupby('A')
    result = grouped.size()
    for key, group in grouped:
        assert result[key] == len(group)

    grouped = df.groupby('B')
    result = grouped.size()
    for key, group in grouped:
        assert result[key] == len(group)

    df = DataFrame(np.random.choice(20, (1000, 3)), columns=list('abc'))
    for sort, key in cart_product((False, True), ('a', 'b', ['a', 'b'])):
        left = df.groupby(key, sort=sort).size()
        right = df.groupby(key, sort=sort)['c'].apply(lambda a: a.shape[0])
        tm.assert_series_equal(left, right, check_names=False)

    # GH11699
    df = DataFrame([], columns=['A', 'B'])
    out = Series([], dtype='int64', index=Index([], name='A'))
    tm.assert_series_equal(df.groupby('A').size(), out)


# pipe
# -------------------------------- 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:32,代码来源:test_function.py

示例12: test_ngroup_cumcount_pair

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import product [as 别名]
def test_ngroup_cumcount_pair(self):
        # brute force comparison for all small series
        for p in cart_product(range(3), repeat=4):
            df = DataFrame({'a': p})
            g = df.groupby(['a'])

            order = sorted(set(p))
            ngroupd = [order.index(val) for val in p]
            cumcounted = [p[:i].count(val) for i, val in enumerate(p)]

            assert_series_equal(g.ngroup(), Series(ngroupd))
            assert_series_equal(g.cumcount(), Series(cumcounted)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_counting.py


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