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


Python offsets.BDay方法代码示例

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


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

示例1: test_shift

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

        shifted = series.shift(0)
        # assert shifted is not series
        tm.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=BDay())
        _dense_series_compare(series, f) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_series.py

示例2: test_shift

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_shift(self):
        shifted = self.rng.shift(5)
        assert shifted[0] == self.rng[5]
        assert shifted.freq == self.rng.freq

        shifted = self.rng.shift(-5)
        assert shifted[5] == self.rng[0]
        assert shifted.freq == self.rng.freq

        shifted = self.rng.shift(0)
        assert shifted[0] == self.rng[0]
        assert shifted.freq == self.rng.freq

        rng = date_range(START, END, freq=BMonthEnd())
        shifted = rng.shift(1, freq=BDay())
        assert shifted[0] == rng[0] + BDay() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_ops.py

示例3: test_asfreq

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_asfreq(self):
        ts = Series([0., 1., 2.], index=[datetime(2009, 10, 30), datetime(
            2009, 11, 30), datetime(2009, 12, 31)])

        daily_ts = ts.asfreq('B')
        monthly_ts = daily_ts.asfreq('BM')
        tm.assert_series_equal(monthly_ts, ts)

        daily_ts = ts.asfreq('B', method='pad')
        monthly_ts = daily_ts.asfreq('BM')
        tm.assert_series_equal(monthly_ts, ts)

        daily_ts = ts.asfreq(BDay())
        monthly_ts = daily_ts.asfreq(BMonthEnd())
        tm.assert_series_equal(monthly_ts, ts)

        result = ts[:0].asfreq('M')
        assert len(result) == 0
        assert result is not ts

        daily_ts = ts.asfreq('D', fill_value=-1)
        result = daily_ts.value_counts().sort_index()
        expected = Series([60, 1, 1, 1],
                          index=[-1.0, 2.0, 1.0, 0.0]).sort_index()
        tm.assert_series_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_timeseries.py

示例4: test_getitem_setitem_boolean_corner

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_getitem_setitem_boolean_corner(test_data):
    ts = test_data.ts
    mask_shifted = ts.shift(1, freq=BDay()) > ts.median()

    # these used to raise...??

    msg = (r"Unalignable boolean Series provided as indexer \(index of"
           r" the boolean Series and of the indexed object do not match")
    with pytest.raises(IndexingError, match=msg):
        ts[mask_shifted]
    with pytest.raises(IndexingError, match=msg):
        ts[mask_shifted] = 1

    with pytest.raises(IndexingError, match=msg):
        ts.loc[mask_shifted]
    with pytest.raises(IndexingError, match=msg):
        ts.loc[mask_shifted] = 1 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_boolean.py

示例5: test_shift

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

        shifted = series.shift(0)
        assert shifted is not series
        tm.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=BDay())
        _dense_series_compare(series, f) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:test_series.py

示例6: SampleLSTM

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def SampleLSTM(ticker:str):
	plot = PlotHelper()
	prices = PricingData(ticker)
	print('Loading ' + ticker)
	CreateFolder(dataFolder + 'samples')
	if prices.LoadHistory():
		prices.NormalizePrices()
		daysInTarget = 15
		daysInTraining = 200
		sampleData = prices.GetPriceHistory()
		endDate  = sampleData.index.max()
		cuttoffDate = endDate - BDay(daysInTarget)
		startDate = cuttoffDate - BDay(daysInTraining)
		print(dataFolder + 'samples/LSTMsampleLearning', startDate, cuttoffDate, endDate)
		plot.PlotDataFrameDateRange(sampleData[['Average']], cuttoffDate, daysInTraining, 'Learn from this series of days', 'Date', 'Price', dataFolder + 'samples/LSTMLearning') 
		plot.PlotDataFrameDateRange(sampleData[['Average']], endDate, daysInTarget, 'Predict what happens after this series of days', 'Date', 'Price', dataFolder + 'samples/LSTMTarget') 
开发者ID:TimRivoli,项目名称:Stock-Price-Trade-Analyzer,代码行数:18,代码来源:PredictionExperiment.py

示例7: test_shift

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_shift(self):
        shifted = self.rng.shift(5)
        assert shifted[0] == self.rng[5]
        assert shifted.offset == self.rng.offset

        shifted = self.rng.shift(-5)
        assert shifted[5] == self.rng[0]
        assert shifted.offset == self.rng.offset

        shifted = self.rng.shift(0)
        assert shifted[0] == self.rng[0]
        assert shifted.offset == self.rng.offset

        rng = date_range(START, END, freq=BMonthEnd())
        shifted = rng.shift(1, freq=BDay())
        assert shifted[0] == rng[0] + BDay() 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:18,代码来源:test_ops.py

示例8: test_getitem_get

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_getitem_get(self):
        idx1 = self.series.index[5]
        idx2 = self.objSeries.index[5]

        assert self.series[idx1] == self.series.get(idx1)
        assert self.objSeries[idx2] == self.objSeries.get(idx2)

        assert self.series[idx1] == self.series[5]
        assert self.objSeries[idx2] == self.objSeries[5]

        assert self.series.get(-1) == self.series.get(self.series.index[-1])
        assert self.series[5] == self.series.get(self.series.index[5])

        # missing
        d = self.ts.index[0] - BDay()
        pytest.raises(KeyError, self.ts.__getitem__, d)

        # None
        # GH 5652
        for s in [Series(), Series(index=list('abc'))]:
            result = s.get(None)
            assert result is None 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:24,代码来源:test_indexing.py

示例9: test_major_xs

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_major_xs(self):
        ref = self.panel['ItemA']

        idx = self.panel.major_axis[5]
        xs = self.panel.major_xs(idx)

        result = xs['ItemA']
        assert_series_equal(result, ref.xs(idx), check_names=False)
        assert result.name == 'ItemA'

        # not contained
        idx = self.panel.major_axis[0] - BDay()
        pytest.raises(Exception, self.panel.major_xs, idx) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_panel.py

示例10: test_tshift

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_tshift(self):
        # PeriodIndex
        ps = tm.makePeriodPanel()
        shifted = ps.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_panel_equal(unshifted, ps)

        shifted2 = ps.tshift(freq='B')
        assert_panel_equal(shifted, shifted2)

        shifted3 = ps.tshift(freq=BDay())
        assert_panel_equal(shifted, shifted3)

        with pytest.raises(ValueError, match='does not match'):
            ps.tshift(freq='M')

        # DatetimeIndex
        panel = make_test_panel()
        shifted = panel.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_panel_equal(panel, unshifted)

        shifted2 = panel.tshift(freq=panel.major_axis.freq)
        assert_panel_equal(shifted, shifted2)

        inferred_ts = Panel(panel.values, items=panel.items,
                            major_axis=Index(np.asarray(panel.major_axis)),
                            minor_axis=panel.minor_axis)
        shifted = inferred_ts.tshift(1)
        unshifted = shifted.tshift(-1)
        assert_panel_equal(shifted, panel.tshift(1))
        assert_panel_equal(unshifted, inferred_ts)

        no_freq = panel.iloc[:, [0, 5, 7], :]
        pytest.raises(ValueError, no_freq.tshift) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:39,代码来源:test_panel.py

示例11: test_getitem

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_getitem(self):
        def _check_getitem(sp, dense):
            for idx, val in compat.iteritems(dense):
                tm.assert_almost_equal(val, sp[idx])

            for i in range(len(dense)):
                tm.assert_almost_equal(sp[i], dense[i])
                # j = np.float64(i)
                # assert_almost_equal(sp[j], dense[j])

                # API change 1/6/2012
                # negative getitem works
                # for i in xrange(len(dense)):
                #     assert_almost_equal(sp[-i], dense[-i])

        _check_getitem(self.bseries, self.bseries.to_dense())
        _check_getitem(self.btseries, self.btseries.to_dense())

        _check_getitem(self.zbseries, self.zbseries.to_dense())
        _check_getitem(self.iseries, self.iseries.to_dense())
        _check_getitem(self.ziseries, self.ziseries.to_dense())

        # exception handling
        pytest.raises(Exception, self.bseries.__getitem__,
                      len(self.bseries) + 1)

        # index not contained
        pytest.raises(Exception, self.btseries.__getitem__,
                      self.btseries.index[-1] + BDay()) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:31,代码来源:test_series.py

示例12: test_shift

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_shift(self, float_frame, float_frame_int_kind, float_frame_dense,
                   float_frame_fill0, float_frame_fill0_dense,
                   float_frame_fill2, float_frame_fill2_dense):

        def _check(frame, orig):
            shifted = frame.shift(0)
            exp = orig.shift(0)
            tm.assert_frame_equal(shifted.to_dense(), exp)

            shifted = frame.shift(1)
            exp = orig.shift(1)
            tm.assert_frame_equal(shifted.to_dense(), exp)

            shifted = frame.shift(-2)
            exp = orig.shift(-2)
            tm.assert_frame_equal(shifted.to_dense(), exp)

            shifted = frame.shift(2, freq='B')
            exp = orig.shift(2, freq='B')
            exp = exp.to_sparse(frame.default_fill_value,
                                kind=frame.default_kind)
            tm.assert_frame_equal(shifted, exp)

            shifted = frame.shift(2, freq=BDay())
            exp = orig.shift(2, freq=BDay())
            exp = exp.to_sparse(frame.default_fill_value,
                                kind=frame.default_kind)
            tm.assert_frame_equal(shifted, exp)

        _check(float_frame, float_frame_dense)
        _check(float_frame_int_kind, float_frame_dense)
        _check(float_frame_fill0, float_frame_fill0_dense)
        _check(float_frame_fill2, float_frame_fill2_dense) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:35,代码来源:test_frame.py

示例13: test_offset_deprecated

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_offset_deprecated(self):
        # GH 20716
        idx = pd.DatetimeIndex(['20180101', '20180102'])

        # getter deprecated
        with tm.assert_produces_warning(FutureWarning):
            idx.offset

        # setter deprecated
        with tm.assert_produces_warning(FutureWarning):
            idx.offset = BDay() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_ops.py

示例14: test_tshift

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_tshift(self):
        # PeriodIndex
        ps = tm.makePeriodSeries()
        shifted = ps.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_series_equal(unshifted, ps)

        shifted2 = ps.tshift(freq='B')
        assert_series_equal(shifted, shifted2)

        shifted3 = ps.tshift(freq=BDay())
        assert_series_equal(shifted, shifted3)

        msg = "Given freq M does not match PeriodIndex freq B"
        with pytest.raises(ValueError, match=msg):
            ps.tshift(freq='M')

        # DatetimeIndex
        shifted = self.ts.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_series_equal(self.ts, unshifted)

        shifted2 = self.ts.tshift(freq=self.ts.index.freq)
        assert_series_equal(shifted, shifted2)

        inferred_ts = Series(self.ts.values, Index(np.asarray(self.ts.index)),
                             name='ts')
        shifted = inferred_ts.tshift(1)
        unshifted = shifted.tshift(-1)
        assert_series_equal(shifted, self.ts.tshift(1))
        assert_series_equal(unshifted, inferred_ts)

        no_freq = self.ts[[0, 5, 7]]
        msg = "Freq was not given and was not set in the index"
        with pytest.raises(ValueError, match=msg):
            no_freq.tshift() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:40,代码来源:test_timeseries.py

示例15: test_frame_setitem_timestamp

# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import BDay [as 别名]
def test_frame_setitem_timestamp(self):
        # GH#2155
        columns = date_range(start='1/1/2012', end='2/1/2012', freq=BDay())
        index = lrange(10)
        data = DataFrame(columns=columns, index=index)
        t = datetime(2012, 11, 1)
        ts = Timestamp(t)
        data[ts] = np.nan  # works, mostly a smoke-test
        assert np.isnan(data[ts]).all() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_indexing.py


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