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


Python pandas.bdate_range方法代码示例

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


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

示例1: test_dti_business_getitem

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_dti_business_getitem(self):
        rng = pd.bdate_range(START, END)
        smaller = rng[:5]
        exp = DatetimeIndex(rng.view(np.ndarray)[:5])
        tm.assert_index_equal(smaller, exp)

        assert smaller.freq == rng.freq

        sliced = rng[::5]
        assert sliced.freq == BDay() * 5

        fancy_indexed = rng[[4, 3, 2, 1, 0]]
        assert len(fancy_indexed) == 5
        assert isinstance(fancy_indexed, DatetimeIndex)
        assert fancy_indexed.freq is None

        # 32-bit vs. 64-bit platforms
        assert rng[4] == rng[np.int_(4)] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_indexing.py

示例2: test_dti_custom_getitem

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_dti_custom_getitem(self):
        rng = pd.bdate_range(START, END, freq='C')
        smaller = rng[:5]
        exp = DatetimeIndex(rng.view(np.ndarray)[:5])
        tm.assert_index_equal(smaller, exp)
        assert smaller.freq == rng.freq

        sliced = rng[::5]
        assert sliced.freq == CDay() * 5

        fancy_indexed = rng[[4, 3, 2, 1, 0]]
        assert len(fancy_indexed) == 5
        assert isinstance(fancy_indexed, DatetimeIndex)
        assert fancy_indexed.freq is None

        # 32-bit vs. 64-bit platforms
        assert rng[4] == rng[np.int_(4)] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_indexing.py

示例3: test_apply_series_to_frame

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_apply_series_to_frame():
    def f(piece):
        with np.errstate(invalid='ignore'):
            logged = np.log(piece)
        return DataFrame({'value': piece,
                          'demeaned': piece - piece.mean(),
                          'logged': logged})

    dr = bdate_range('1/1/2000', periods=100)
    ts = Series(np.random.randn(100), index=dr)

    grouped = ts.groupby(lambda x: x.month)
    result = grouped.apply(f)

    assert isinstance(result, DataFrame)
    tm.assert_index_equal(result.index, ts.index) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_apply.py

示例4: test_resample_bms_2752

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_resample_bms_2752(self):
        # GH2753
        foo = Series(index=pd.bdate_range('20000101', '20000201'))
        res1 = foo.resample("BMS").mean()
        res2 = foo.resample("BMS").mean().resample("B").mean()
        assert res1.index[0] == Timestamp('20000103')
        assert res1.index[0] == res2.index[0]

    # def test_monthly_convention_span(self):
    #     rng = period_range('2000-01', periods=3, freq='M')
    #     ts = Series(np.arange(3), index=rng)

    #     # hacky way to get same thing
    #     exp_index = period_range('2000-01-01', '2000-03-31', freq='D')
    #     expected = ts.asfreq('D', how='end').reindex(exp_index)
    #     expected = expected.fillna(method='bfill')

    #     result = ts.resample('D', convention='span').mean()

    #     assert_series_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_period_index.py

示例5: test_shift

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_shift(self):
        series = SparseSeries([nan, 1., 2., 3., nan, nan],
                              index=np.arange(6))

        shifted = series.shift(0)
        self.assert_(shifted is not series)
        assert_sp_series_equal(shifted, series)

        f = lambda s: s.shift(1)
        _dense_series_compare(series, f)

        f = lambda s: s.shift(-2)
        _dense_series_compare(series, f)

        series = SparseSeries([nan, 1., 2., 3., nan, nan],
                              index=bdate_range('1/1/2000', periods=6))
        f = lambda s: s.shift(2, freq='B')
        _dense_series_compare(series, f)

        f = lambda s: s.shift(2, freq=datetools.bday)
        _dense_series_compare(series, f) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_sparse.py

示例6: test_resample_bms_2752

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_resample_bms_2752(self):
        # GH2753
        foo = pd.Series(index=pd.bdate_range('20000101','20000201'))
        res1 = foo.resample("BMS")
        res2 = foo.resample("BMS").resample("B")
        self.assertEqual(res1.index[0], Timestamp('20000103'))
        self.assertEqual(res1.index[0], res2.index[0])

    # def test_monthly_convention_span(self):
    #     rng = period_range('2000-01', periods=3, freq='M')
    #     ts = Series(np.arange(3), index=rng)

    #     # hacky way to get same thing
    #     exp_index = period_range('2000-01-01', '2000-03-31', freq='D')
    #     expected = ts.asfreq('D', how='end').reindex(exp_index)
    #     expected = expected.fillna(method='bfill')

    #     result = ts.resample('D', convention='span')

    #     assert_series_equal(result, expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:test_resample.py

示例7: test_legacy_time_rule_arg

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_legacy_time_rule_arg(self):
        # suppress deprecation warnings
        sys.stderr = StringIO()

        rng = bdate_range('1/1/2000', periods=20)
        ts = Series(np.random.randn(20), index=rng)
        ts = ts.take(np.random.permutation(len(ts))[:12]).sort_index()

        try:
            result = mom.rolling_mean(ts, 1, min_periods=1, freq='B')
            expected = mom.rolling_mean(ts, 1, min_periods=1,
                                        time_rule='WEEKDAY')
            tm.assert_series_equal(result, expected)

            result = mom.ewma(ts, span=5, freq='B')
            expected = mom.ewma(ts, span=5, time_rule='WEEKDAY')
            tm.assert_series_equal(result, expected)

        finally:
            sys.stderr = sys.__stderr__ 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:test_moments.py

示例8: _create_sp_tsseries

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def _create_sp_tsseries():

    import numpy as np
    from pandas import bdate_range, SparseTimeSeries

    nan = np.nan

    # nan-based
    arr = np.arange(15, dtype=np.float64)
    index = np.arange(15)
    arr[7:12] = nan
    arr[-1:] = nan

    date_index = bdate_range('1/1/2011', periods=len(index))
    bseries = SparseTimeSeries(arr, index=date_index, kind='block')
    bseries.name = 'btsseries'
    return bseries 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:generate_legacy_pickles.py

示例9: test_reindex_fill_value

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_reindex_fill_value(self, float_frame_fill0,
                                float_frame_fill0_dense):
        rng = bdate_range('20110110', periods=20)

        result = float_frame_fill0.reindex(rng, fill_value=0)
        exp = float_frame_fill0_dense.reindex(rng, fill_value=0)
        exp = exp.to_sparse(float_frame_fill0.default_fill_value)
        tm.assert_sp_frame_equal(result, exp) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_frame.py

示例10: dates

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def dates():
    return bdate_range('1/1/2011', periods=10) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:test_apply.py

示例11: test_dti_business_getitem_matplotlib_hackaround

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_dti_business_getitem_matplotlib_hackaround(self):
        rng = pd.bdate_range(START, END)
        values = rng[:, None]
        expected = rng.values[:, None]
        tm.assert_numpy_array_equal(values, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_indexing.py

示例12: test_dti_tz_localize_bdate_range

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_dti_tz_localize_bdate_range(self):
        dr = pd.bdate_range('1/1/2009', '1/1/2010')
        dr_utc = pd.bdate_range('1/1/2009', '1/1/2010', tz=pytz.utc)
        localized = dr.tz_localize(pytz.utc)
        tm.assert_index_equal(dr_utc, localized) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_timezones.py

示例13: test_with_tz

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_with_tz(self, tz):
        # just want it to work
        start = datetime(2011, 3, 12, tzinfo=pytz.utc)
        dr = bdate_range(start, periods=50, freq=pd.offsets.Hour())
        assert dr.tz is pytz.utc

        # DateRange with naive datetimes
        dr = bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc)
        dr = bdate_range('1/1/2005', '1/1/2009', tz=tz)

        # normalized
        central = dr.tz_convert(tz)
        assert central.tz is tz
        naive = central[0].to_pydatetime().replace(tzinfo=None)
        comp = conversion.localize_pydatetime(naive, tz).tzinfo
        assert central[0].tz is comp

        # compare vs a localized tz
        naive = dr[0].to_pydatetime().replace(tzinfo=None)
        comp = conversion.localize_pydatetime(naive, tz).tzinfo
        assert central[0].tz is comp

        # datetimes with tzinfo set
        dr = bdate_range(datetime(2005, 1, 1, tzinfo=pytz.utc),
                         datetime(2009, 1, 1, tzinfo=pytz.utc))
        with pytest.raises(Exception):
            bdate_range(datetime(2005, 1, 1, tzinfo=pytz.utc), '1/1/2009',
                        tz=tz) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:30,代码来源:test_timezones.py

示例14: test_constructor

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_constructor(self):
        bdate_range(START, END, freq=BDay())
        bdate_range(START, periods=20, freq=BDay())
        bdate_range(end=START, periods=20, freq=BDay())

        msg = 'periods must be a number, got B'
        with pytest.raises(TypeError, match=msg):
            date_range('2011-1-1', '2012-1-1', 'B')

        with pytest.raises(TypeError, match=msg):
            bdate_range('2011-1-1', '2012-1-1', 'B')

        msg = 'freq must be specified for bdate_range; use date_range instead'
        with pytest.raises(TypeError, match=msg):
            bdate_range(START, END, periods=10, freq=None) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_date_range.py

示例15: test_naive_aware_conflicts

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import bdate_range [as 别名]
def test_naive_aware_conflicts(self):
        naive = bdate_range(START, END, freq=BDay(), tz=None)
        aware = bdate_range(START, END, freq=BDay(), tz="Asia/Hong_Kong")

        msg = 'tz-naive.*tz-aware'
        with pytest.raises(TypeError, match=msg):
            naive.join(aware)

        with pytest.raises(TypeError, match=msg):
            aware.join(naive) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_date_range.py


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