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


Python compat.lmap方法代码示例

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


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

示例1: test_map_with_string_constructor

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_map_with_string_constructor(self):
        raw = [2005, 2007, 2009]
        index = PeriodIndex(raw, freq='A')
        types = str,

        if PY3:
            # unicode
            types += text_type,

        for t in types:
            expected = Index(lmap(t, raw))
            res = index.map(t)

            # should return an Index
            assert isinstance(res, Index)

            # preserve element types
            assert all(isinstance(resi, t) for resi in res)

            # lastly, values should compare equal
            tm.assert_index_equal(res, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_construction.py

示例2: test_kde_colors

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_kde_colors(self):
        _skip_if_no_scipy_gaussian_kde()

        from matplotlib import cm

        custom_colors = 'rgcby'
        df = DataFrame(rand(5, 5))

        ax = df.plot.kde(color=custom_colors)
        self._check_colors(ax.get_lines(), linecolors=custom_colors)
        tm.close()

        ax = df.plot.kde(colormap='jet')
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
        self._check_colors(ax.get_lines(), linecolors=rgba_colors)
        tm.close()

        ax = df.plot.kde(colormap=cm.jet)
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
        self._check_colors(ax.get_lines(), linecolors=rgba_colors) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_frame.py

示例3: applymap

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def applymap(self, func):
        """
        Apply a function to a DataFrame that is intended to operate
        elementwise, i.e. like doing map(func, series) for each series in the
        DataFrame

        Parameters
        ----------
        func : function
            Python function, returns a single value from a single value

        Returns
        -------
        applied : DataFrame
        """
        return self.apply(lambda x: lmap(func, x)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:frame.py

示例4: is_one_of_factory

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def is_one_of_factory(legal_values):

    callables = [c for c in legal_values if callable(c)]
    legal_values = [c for c in legal_values if not callable(c)]

    def inner(x):
        from pandas.io.formats.printing import pprint_thing as pp
        if x not in legal_values:

            if not any(c(x) for c in callables):
                pp_values = pp("|".join(lmap(pp, legal_values)))
                msg = "Value must be one of {pp_values}"
                if len(callables):
                    msg += " or a callable"
                raise ValueError(msg.format(pp_values=pp_values))

    return inner


# common type validators, for convenience
# usage: register_option(... , validator = is_int) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:config.py

示例5: test_kde_colors

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_kde_colors(self):
        _skip_if_no_scipy_gaussian_kde()
        if not self.mpl_ge_1_5_0:
            pytest.skip("mpl is not supported")

        from matplotlib import cm

        custom_colors = 'rgcby'
        df = DataFrame(rand(5, 5))

        ax = df.plot.kde(color=custom_colors)
        self._check_colors(ax.get_lines(), linecolors=custom_colors)
        tm.close()

        ax = df.plot.kde(colormap='jet')
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
        self._check_colors(ax.get_lines(), linecolors=rgba_colors)
        tm.close()

        ax = df.plot.kde(colormap=cm.jet)
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
        self._check_colors(ax.get_lines(), linecolors=rgba_colors) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_frame.py

示例6: test_map_with_string_constructor

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_map_with_string_constructor(self):
        raw = [2005, 2007, 2009]
        index = PeriodIndex(raw, freq='A')
        types = str,

        if compat.PY3:
            # unicode
            types += compat.text_type,

        for t in types:
            expected = np.array(lmap(t, raw), dtype=object)
            res = index.map(t)

            # should return an array
            tm.assert_isinstance(res, np.ndarray)

            # preserve element types
            self.assert_(all(isinstance(resi, t) for resi in res))

            # dtype should be object
            self.assertEqual(res.dtype, np.dtype('object').type)

            # lastly, values should compare equal
            assert_array_equal(res, expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:test_period.py

示例7: is_one_of_factory

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def is_one_of_factory(legal_values):

    callables = [c for c in legal_values if callable(c)]
    legal_values = [c for c in legal_values if not callable(c)]

    def inner(x):
        from pandas.io.formats.printing import pprint_thing as pp
        if x not in legal_values:

            if not any([c(x) for c in callables]):
                pp_values = pp("|".join(lmap(pp, legal_values)))
                msg = "Value must be one of {pp_values}"
                if len(callables):
                    msg += " or a callable"
                raise ValueError(msg.format(pp_values=pp_values))

    return inner


# common type validators, for convenience
# usage: register_option(... , validator = is_int) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:23,代码来源:config.py

示例8: test_kde_colors

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_kde_colors(self):
        tm._skip_if_no_scipy()
        _skip_if_no_scipy_gaussian_kde()
        if not self.mpl_ge_1_5_0:
            pytest.skip("mpl is not supported")

        from matplotlib import cm

        custom_colors = 'rgcby'
        df = DataFrame(rand(5, 5))

        ax = df.plot.kde(color=custom_colors)
        self._check_colors(ax.get_lines(), linecolors=custom_colors)
        tm.close()

        ax = df.plot.kde(colormap='jet')
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
        self._check_colors(ax.get_lines(), linecolors=rgba_colors)
        tm.close()

        ax = df.plot.kde(colormap=cm.jet)
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
        self._check_colors(ax.get_lines(), linecolors=rgba_colors) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:25,代码来源:test_frame.py

示例9: autocorrelation_plot

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def autocorrelation_plot(series, ax=None, **kwds):
    """Autocorrelation plot for time series.

    Parameters:
    -----------
    series: Time series
    ax: Matplotlib axis object, optional
    kwds : keywords
        Options to pass to matplotlib plotting method

    Returns:
    -----------
    ax: Matplotlib axis object
    """
    import matplotlib.pyplot as plt
    n = len(series)
    data = np.asarray(series)
    if ax is None:
        ax = plt.gca(xlim=(1, n), ylim=(-1.0, 1.0))
    mean = np.mean(data)
    c0 = np.sum((data - mean) ** 2) / float(n)

    def r(h):
        return ((data[:n - h] - mean) *
                (data[h:] - mean)).sum() / float(n) / c0
    x = np.arange(n) + 1
    y = lmap(r, x)
    z95 = 1.959963984540054
    z99 = 2.5758293035489004
    ax.axhline(y=z99 / np.sqrt(n), linestyle='--', color='grey')
    ax.axhline(y=z95 / np.sqrt(n), color='grey')
    ax.axhline(y=0.0, color='black')
    ax.axhline(y=-z95 / np.sqrt(n), color='grey')
    ax.axhline(y=-z99 / np.sqrt(n), linestyle='--', color='grey')
    ax.set_xlabel("Lag")
    ax.set_ylabel("Autocorrelation")
    ax.plot(x, y, **kwds)
    if 'label' in kwds:
        ax.legend()
    ax.grid()
    return ax 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:43,代码来源:_misc.py

示例10: test_to_datetime_types

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_to_datetime_types(self, cache):

        # empty string
        result = to_datetime('', cache=cache)
        assert result is NaT

        result = to_datetime(['', ''], cache=cache)
        assert isna(result).all()

        # ints
        result = Timestamp(0)
        expected = to_datetime(0, cache=cache)
        assert result == expected

        # GH 3888 (strings)
        expected = to_datetime(['2012'], cache=cache)[0]
        result = to_datetime('2012', cache=cache)
        assert result == expected

        # array = ['2012','20120101','20120101 12:01:01']
        array = ['20120101', '20120101 12:01:01']
        expected = list(to_datetime(array, cache=cache))
        result = lmap(Timestamp, array)
        tm.assert_almost_equal(result, expected)

        # currently fails ###
        # result = Timestamp('2012')
        # expected = to_datetime('2012')
        # assert result == expected 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:31,代码来源:test_tools.py

示例11: test_radviz

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_radviz(self, iris):
        from pandas.plotting import radviz
        from matplotlib import cm

        df = iris
        _check_plot_works(radviz, frame=df, class_column='Name')

        rgba = ('#556270', '#4ECDC4', '#C7F464')
        ax = _check_plot_works(
            radviz, frame=df, class_column='Name', color=rgba)
        # skip Circle drawn as ticks
        patches = [p for p in ax.patches[:20] if p.get_label() != '']
        self._check_colors(
            patches[:10], facecolors=rgba, mapping=df['Name'][:10])

        cnames = ['dodgerblue', 'aquamarine', 'seagreen']
        _check_plot_works(radviz, frame=df, class_column='Name', color=cnames)
        patches = [p for p in ax.patches[:20] if p.get_label() != '']
        self._check_colors(patches, facecolors=cnames, mapping=df['Name'][:10])

        _check_plot_works(radviz, frame=df,
                          class_column='Name', colormap=cm.jet)
        cmaps = lmap(cm.jet, np.linspace(0, 1, df['Name'].nunique()))
        patches = [p for p in ax.patches[:20] if p.get_label() != '']
        self._check_colors(patches, facecolors=cmaps, mapping=df['Name'][:10])

        colors = [[0., 0., 1., 1.],
                  [0., 0.5, 1., 1.],
                  [1., 0., 0., 1.]]
        df = DataFrame({"A": [1, 2, 3],
                        "B": [2, 1, 3],
                        "C": [3, 2, 1],
                        "Name": ['b', 'g', 'r']})
        ax = radviz(df, 'Name', color=colors)
        handles, labels = ax.get_legend_handles_labels()
        self._check_colors(handles, facecolors=colors) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:38,代码来源:test_misc.py

示例12: test_bar_colors

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_bar_colors(self):
        import matplotlib.pyplot as plt
        default_colors = self._unpack_cycler(plt.rcParams)

        df = DataFrame(randn(5, 5))
        ax = df.plot.bar()
        self._check_colors(ax.patches[::5], facecolors=default_colors[:5])
        tm.close()

        custom_colors = 'rgcby'
        ax = df.plot.bar(color=custom_colors)
        self._check_colors(ax.patches[::5], facecolors=custom_colors)
        tm.close()

        from matplotlib import cm
        # Test str -> colormap functionality
        ax = df.plot.bar(colormap='jet')
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, 5))
        self._check_colors(ax.patches[::5], facecolors=rgba_colors)
        tm.close()

        # Test colormap functionality
        ax = df.plot.bar(colormap=cm.jet)
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, 5))
        self._check_colors(ax.patches[::5], facecolors=rgba_colors)
        tm.close()

        ax = df.loc[:, [0]].plot.bar(color='DodgerBlue')
        self._check_colors([ax.patches[0]], facecolors=['DodgerBlue'])
        tm.close()

        ax = df.plot(kind='bar', color='green')
        self._check_colors(ax.patches[::5], facecolors=['green'] * 5)
        tm.close() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:36,代码来源:test_frame.py

示例13: test_hist_colors

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def test_hist_colors(self):
        default_colors = self._unpack_cycler(self.plt.rcParams)

        df = DataFrame(randn(5, 5))
        ax = df.plot.hist()
        self._check_colors(ax.patches[::10], facecolors=default_colors[:5])
        tm.close()

        custom_colors = 'rgcby'
        ax = df.plot.hist(color=custom_colors)
        self._check_colors(ax.patches[::10], facecolors=custom_colors)
        tm.close()

        from matplotlib import cm
        # Test str -> colormap functionality
        ax = df.plot.hist(colormap='jet')
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, 5))
        self._check_colors(ax.patches[::10], facecolors=rgba_colors)
        tm.close()

        # Test colormap functionality
        ax = df.plot.hist(colormap=cm.jet)
        rgba_colors = lmap(cm.jet, np.linspace(0, 1, 5))
        self._check_colors(ax.patches[::10], facecolors=rgba_colors)
        tm.close()

        ax = df.loc[:, [0]].plot.hist(color='DodgerBlue')
        self._check_colors([ax.patches[0]], facecolors=['DodgerBlue'])

        ax = df.plot(kind='hist', color='green')
        self._check_colors(ax.patches[::10], facecolors=['green'] * 5)
        tm.close() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:34,代码来源:test_frame.py

示例14: test_to_csv_from_csv3

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

        with ensure_clean('__tmp_to_csv_from_csv3__') as path:
            df1 = DataFrame(np.random.randn(3, 1))
            df2 = DataFrame(np.random.randn(3, 1))

            df1.to_csv(path)
            df2.to_csv(path, mode='a', header=False)
            xp = pd.concat([df1, df2])
            rs = pd.read_csv(path, index_col=0)
            rs.columns = lmap(int, rs.columns)
            xp.columns = lmap(int, xp.columns)
            assert_frame_equal(xp, rs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_to_csv.py

示例15: _preparse

# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import lmap [as 别名]
def _preparse(source, f=_compose(_replace_locals, _replace_booleans,
                                 _rewrite_assign)):
    """Compose a collection of tokenization functions

    Parameters
    ----------
    source : str
        A Python source code string
    f : callable
        This takes a tuple of (toknum, tokval) as its argument and returns a
        tuple with the same structure but possibly different elements. Defaults
        to the composition of ``_rewrite_assign``, ``_replace_booleans``, and
        ``_replace_locals``.

    Returns
    -------
    s : str
        Valid Python source code

    Notes
    -----
    The `f` parameter can be any callable that takes *and* returns input of the
    form ``(toknum, tokval)``, where ``toknum`` is one of the constants from
    the ``tokenize`` module and ``tokval`` is a string.
    """
    assert callable(f), 'f must be callable'
    return tokenize.untokenize(lmap(f, tokenize_string(source))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:29,代码来源:expr.py


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