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


Python pandas.Period类代码示例

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


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

示例1: test_construction

    def test_construction(self):
        i1 = Period('1/1/2005', freq='M')
        i2 = Period('Jan 2005')

        assert i1 == i2

        i1 = Period('2005', freq='A')
        i2 = Period('2005')
        i3 = Period('2005', freq='a')

        assert i1 == i2
        assert i1 == i3

        i4 = Period('2005', freq='M')
        i5 = Period('2005', freq='m')

        pytest.raises(ValueError, i1.__ne__, i4)
        assert i4 == i5

        i1 = Period.now('Q')
        i2 = Period(datetime.now(), freq='Q')
        i3 = Period.now('q')

        assert i1 == i2
        assert i1 == i3

        i1 = Period('1982', freq='min')
        i2 = Period('1982', freq='MIN')
        assert i1 == i2
        i2 = Period('1982', freq=('Min', 1))
        assert i1 == i2

        i1 = Period(year=2005, month=3, day=1, freq='D')
        i2 = Period('3/1/2005', freq='D')
        assert i1 == i2

        i3 = Period(year=2005, month=3, day=1, freq='d')
        assert i1 == i3

        i1 = Period('2007-01-01 09:00:00.001')
        expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1000), freq='L')
        assert i1 == expected

        expected = Period(np_datetime64_compat(
            '2007-01-01 09:00:00.001Z'), freq='L')
        assert i1 == expected

        i1 = Period('2007-01-01 09:00:00.00101')
        expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1010), freq='U')
        assert i1 == expected

        expected = Period(np_datetime64_compat('2007-01-01 09:00:00.00101Z'),
                          freq='U')
        assert i1 == expected

        pytest.raises(ValueError, Period, ordinal=200701)

        pytest.raises(ValueError, Period, '2007-1-1', freq='X')
开发者ID:MichaelWS,项目名称:pandas,代码行数:58,代码来源:test_period.py

示例2: test_asfreq_corner

 def test_asfreq_corner(self):
     val = Period(freq='A', year=2007)
     result1 = val.asfreq('5t')
     result2 = val.asfreq('t')
     expected = Period('2007-12-31 23:59', freq='t')
     self.assertEqual(result1.ordinal, expected.ordinal)
     self.assertEqual(result1.freqstr, '5T')
     self.assertEqual(result2.ordinal, expected.ordinal)
     self.assertEqual(result2.freqstr, 'T')
开发者ID:RogerThomas,项目名称:pandas,代码行数:9,代码来源:test_period_asfreq.py

示例3: test_asfreq_near_zero_weekly

 def test_asfreq_near_zero_weekly(self):
     # GH#19834
     per1 = Period('0001-01-01', 'D') + 6
     per2 = Period('0001-01-01', 'D') - 6
     week1 = per1.asfreq('W')
     week2 = per2.asfreq('W')
     assert week1 != week2
     assert week1.asfreq('D', 'E') >= per1
     assert week2.asfreq('D', 'S') <= per2
开发者ID:DusanMilunovic,项目名称:pandas,代码行数:9,代码来源:test_asfreq.py

示例4: test_asfreq_corner

 def test_asfreq_corner(self):
     val = Period(freq='A', year=2007)
     result1 = val.asfreq('5t')
     result2 = val.asfreq('t')
     expected = Period('2007-12-31 23:59', freq='t')
     assert result1.ordinal == expected.ordinal
     assert result1.freqstr == '5T'
     assert result2.ordinal == expected.ordinal
     assert result2.freqstr == 'T'
开发者ID:DusanMilunovic,项目名称:pandas,代码行数:9,代码来源:test_asfreq.py

示例5: test_period_cons_annual

 def test_period_cons_annual(self):
     # bugs in scikits.timeseries
     for month in MONTHS:
         freq = 'A-%s' % month
         exp = Period('1989', freq=freq)
         stamp = exp.to_timestamp('D', how='end') + timedelta(days=30)
         p = Period(stamp, freq=freq)
         assert p == exp + 1
         assert isinstance(p, Period)
开发者ID:MichaelWS,项目名称:pandas,代码行数:9,代码来源:test_period.py

示例6: test_asfreq_near_zero_weekly

 def test_asfreq_near_zero_weekly(self):
     # GH#19834
     with tm.assert_produces_warning(FutureWarning):
         per1 = Period('0001-01-01', 'D') + 6
         per2 = Period('0001-01-01', 'D') - 6
     week1 = per1.asfreq('W')
     week2 = per2.asfreq('W')
     assert week1 != week2
     assert week1.asfreq('D', 'E') >= per1
     assert week2.asfreq('D', 'S') <= per2
开发者ID:christlc,项目名称:pandas,代码行数:10,代码来源:test_asfreq.py

示例7: test_asfreq_MS

    def test_asfreq_MS(self):
        initial = Period("2013")

        assert initial.asfreq(freq="M", how="S") == Period('2013-01', 'M')

        msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
        with tm.assert_raises_regex(ValueError, msg):
            initial.asfreq(freq="MS", how="S")

        with tm.assert_raises_regex(ValueError, msg):
            pd.Period('2013-01', 'MS')

        assert _period_code_map.get("MS") is None
开发者ID:BobMcFry,项目名称:pandas,代码行数:13,代码来源:test_asfreq.py

示例8: test_period_cons_quarterly

    def test_period_cons_quarterly(self):
        # bugs in scikits.timeseries
        for month in MONTHS:
            freq = 'Q-%s' % month
            exp = Period('1989Q3', freq=freq)
            assert '1989Q3' in str(exp)
            stamp = exp.to_timestamp('D', how='end')
            p = Period(stamp, freq=freq)
            assert p == exp

            stamp = exp.to_timestamp('3D', how='end')
            p = Period(stamp, freq=freq)
            assert p == exp
开发者ID:MichaelWS,项目名称:pandas,代码行数:13,代码来源:test_period.py

示例9: test_asfreq_MS

    def test_asfreq_MS(self):
        initial = Period("2013")

        assert initial.asfreq(freq="M", how="S") == Period('2013-01', 'M')

        msg = INVALID_FREQ_ERR_MSG
        with pytest.raises(ValueError, match=msg):
            initial.asfreq(freq="MS", how="S")

        with pytest.raises(ValueError, match=msg):
            Period('2013-01', 'MS')

        assert _period_code_map.get("MS") is None
开发者ID:DusanMilunovic,项目名称:pandas,代码行数:13,代码来源:test_asfreq.py

示例10: test_asfreq_MS

    def test_asfreq_MS(self):
        initial = Period("2013")

        self.assertEqual(initial.asfreq(freq="M", how="S"),
                         Period('2013-01', 'M'))

        msg = pd.tseries.frequencies._INVALID_FREQ_ERROR
        with self.assertRaisesRegexp(ValueError, msg):
            initial.asfreq(freq="MS", how="S")

        with tm.assertRaisesRegexp(ValueError, msg):
            pd.Period('2013-01', 'MS')

        self.assertTrue(_period_code_map.get("MS") is None)
开发者ID:RogerThomas,项目名称:pandas,代码行数:14,代码来源:test_period_asfreq.py

示例11: Properties

class Properties(object):
    def setup(self):
        self.per = Period('2017-09-06 08:28', freq='min')

    def time_year(self):
        self.per.year

    def time_month(self):
        self.per.month

    def time_day(self):
        self.per.day

    def time_hour(self):
        self.per.hour

    def time_minute(self):
        self.per.minute

    def time_second(self):
        self.per.second

    def time_is_leap_year(self):
        self.per.is_leap_year

    def time_quarter(self):
        self.per.quarter

    def time_qyear(self):
        self.per.qyear

    def time_week(self):
        self.per.week

    def time_daysinmonth(self):
        self.per.daysinmonth

    def time_dayofweek(self):
        self.per.dayofweek

    def time_dayofyear(self):
        self.per.dayofyear

    def time_start_time(self):
        self.per.start_time

    def time_end_time(self):
        self.per.end_time

    def time_to_timestamp():
        self.per.to_timestamp()

    def time_now():
        self.per.now()

    def time_asfreq():
        self.per.asfreq('A')
开发者ID:Axik,项目名称:pandas,代码行数:57,代码来源:period.py

示例12: test_construction_bday

    def test_construction_bday(self):

        # Biz day construction, roll forward if non-weekday
        i1 = Period('3/10/12', freq='B')
        i2 = Period('3/10/12', freq='D')
        assert i1 == i2.asfreq('B')
        i2 = Period('3/11/12', freq='D')
        assert i1 == i2.asfreq('B')
        i2 = Period('3/12/12', freq='D')
        assert i1 == i2.asfreq('B')

        i3 = Period('3/10/12', freq='b')
        assert i1 == i3

        i1 = Period(year=2012, month=3, day=10, freq='B')
        i2 = Period('3/12/12', freq='B')
        assert i1 == i2
开发者ID:MichaelWS,项目名称:pandas,代码行数:17,代码来源:test_period.py

示例13: PeriodUnaryMethods

class PeriodUnaryMethods(object):
    params = ['M', 'min']
    param_names = ['freq']

    def setup(self, freq):
        self.per = Period('2012-06-01', freq=freq)

    def time_to_timestamp(self, freq):
        self.per.to_timestamp()

    def time_now(self, freq):
        self.per.now(freq)

    def time_asfreq(self, freq):
        self.per.asfreq('A')
开发者ID:Xbar,项目名称:pandas,代码行数:15,代码来源:period.py

示例14: test_asfreq_combined

    def test_asfreq_combined(self):
        # normal freq to combined freq
        p = Period('2007', freq='H')

        # ordinal will not change
        expected = Period('2007', freq='25H')
        for freq, how in zip(['1D1H', '1H1D'], ['E', 'S']):
            result = p.asfreq(freq, how=how)
            assert result == expected
            assert result.ordinal == expected.ordinal
            assert result.freq == expected.freq

        # combined freq to normal freq
        p1 = Period(freq='1D1H', year=2007)
        p2 = Period(freq='1H1D', year=2007)

        # ordinal will change because how=E is the default
        result1 = p1.asfreq('H')
        result2 = p2.asfreq('H')
        expected = Period('2007-01-02', freq='H')
        assert result1 == expected
        assert result1.ordinal == expected.ordinal
        assert result1.freq == expected.freq
        assert result2 == expected
        assert result2.ordinal == expected.ordinal
        assert result2.freq == expected.freq

        # ordinal will not change
        result1 = p1.asfreq('H', how='S')
        result2 = p2.asfreq('H', how='S')
        expected = Period('2007-01-01', freq='H')
        assert result1 == expected
        assert result1.ordinal == expected.ordinal
        assert result1.freq == expected.freq
        assert result2 == expected
        assert result2.ordinal == expected.ordinal
        assert result2.freq == expected.freq
开发者ID:DusanMilunovic,项目名称:pandas,代码行数:37,代码来源:test_asfreq.py

示例15: test_conv_weekly

    def test_conv_weekly(self):
        # frequency conversion tests: from Weekly Frequency
        ival_W = Period(freq='W', year=2007, month=1, day=1)

        ival_WSUN = Period(freq='W', year=2007, month=1, day=7)
        ival_WSAT = Period(freq='W-SAT', year=2007, month=1, day=6)
        ival_WFRI = Period(freq='W-FRI', year=2007, month=1, day=5)
        ival_WTHU = Period(freq='W-THU', year=2007, month=1, day=4)
        ival_WWED = Period(freq='W-WED', year=2007, month=1, day=3)
        ival_WTUE = Period(freq='W-TUE', year=2007, month=1, day=2)
        ival_WMON = Period(freq='W-MON', year=2007, month=1, day=1)

        ival_WSUN_to_D_start = Period(freq='D', year=2007, month=1, day=1)
        ival_WSUN_to_D_end = Period(freq='D', year=2007, month=1, day=7)
        ival_WSAT_to_D_start = Period(freq='D', year=2006, month=12, day=31)
        ival_WSAT_to_D_end = Period(freq='D', year=2007, month=1, day=6)
        ival_WFRI_to_D_start = Period(freq='D', year=2006, month=12, day=30)
        ival_WFRI_to_D_end = Period(freq='D', year=2007, month=1, day=5)
        ival_WTHU_to_D_start = Period(freq='D', year=2006, month=12, day=29)
        ival_WTHU_to_D_end = Period(freq='D', year=2007, month=1, day=4)
        ival_WWED_to_D_start = Period(freq='D', year=2006, month=12, day=28)
        ival_WWED_to_D_end = Period(freq='D', year=2007, month=1, day=3)
        ival_WTUE_to_D_start = Period(freq='D', year=2006, month=12, day=27)
        ival_WTUE_to_D_end = Period(freq='D', year=2007, month=1, day=2)
        ival_WMON_to_D_start = Period(freq='D', year=2006, month=12, day=26)
        ival_WMON_to_D_end = Period(freq='D', year=2007, month=1, day=1)

        ival_W_end_of_year = Period(freq='W', year=2007, month=12, day=31)
        ival_W_end_of_quarter = Period(freq='W', year=2007, month=3, day=31)
        ival_W_end_of_month = Period(freq='W', year=2007, month=1, day=31)
        ival_W_to_A = Period(freq='A', year=2007)
        ival_W_to_Q = Period(freq='Q', year=2007, quarter=1)
        ival_W_to_M = Period(freq='M', year=2007, month=1)

        if Period(freq='D', year=2007, month=12, day=31).weekday == 6:
            ival_W_to_A_end_of_year = Period(freq='A', year=2007)
        else:
            ival_W_to_A_end_of_year = Period(freq='A', year=2008)

        if Period(freq='D', year=2007, month=3, day=31).weekday == 6:
            ival_W_to_Q_end_of_quarter = Period(freq='Q', year=2007, quarter=1)
        else:
            ival_W_to_Q_end_of_quarter = Period(freq='Q', year=2007, quarter=2)

        if Period(freq='D', year=2007, month=1, day=31).weekday == 6:
            ival_W_to_M_end_of_month = Period(freq='M', year=2007, month=1)
        else:
            ival_W_to_M_end_of_month = Period(freq='M', year=2007, month=2)

        ival_W_to_B_start = Period(freq='B', year=2007, month=1, day=1)
        ival_W_to_B_end = Period(freq='B', year=2007, month=1, day=5)
        ival_W_to_D_start = Period(freq='D', year=2007, month=1, day=1)
        ival_W_to_D_end = Period(freq='D', year=2007, month=1, day=7)
        ival_W_to_H_start = Period(freq='H', year=2007, month=1, day=1, hour=0)
        ival_W_to_H_end = Period(freq='H', year=2007, month=1, day=7, hour=23)
        ival_W_to_T_start = Period(freq='Min', year=2007, month=1, day=1,
                                   hour=0, minute=0)
        ival_W_to_T_end = Period(freq='Min', year=2007, month=1, day=7,
                                 hour=23, minute=59)
        ival_W_to_S_start = Period(freq='S', year=2007, month=1, day=1, hour=0,
                                   minute=0, second=0)
        ival_W_to_S_end = Period(freq='S', year=2007, month=1, day=7, hour=23,
                                 minute=59, second=59)

        assert ival_W.asfreq('A') == ival_W_to_A
        assert ival_W_end_of_year.asfreq('A') == ival_W_to_A_end_of_year

        assert ival_W.asfreq('Q') == ival_W_to_Q
        assert ival_W_end_of_quarter.asfreq('Q') == ival_W_to_Q_end_of_quarter

        assert ival_W.asfreq('M') == ival_W_to_M
        assert ival_W_end_of_month.asfreq('M') == ival_W_to_M_end_of_month

        assert ival_W.asfreq('B', 'S') == ival_W_to_B_start
        assert ival_W.asfreq('B', 'E') == ival_W_to_B_end

        assert ival_W.asfreq('D', 'S') == ival_W_to_D_start
        assert ival_W.asfreq('D', 'E') == ival_W_to_D_end

        assert ival_WSUN.asfreq('D', 'S') == ival_WSUN_to_D_start
        assert ival_WSUN.asfreq('D', 'E') == ival_WSUN_to_D_end
        assert ival_WSAT.asfreq('D', 'S') == ival_WSAT_to_D_start
        assert ival_WSAT.asfreq('D', 'E') == ival_WSAT_to_D_end
        assert ival_WFRI.asfreq('D', 'S') == ival_WFRI_to_D_start
        assert ival_WFRI.asfreq('D', 'E') == ival_WFRI_to_D_end
        assert ival_WTHU.asfreq('D', 'S') == ival_WTHU_to_D_start
        assert ival_WTHU.asfreq('D', 'E') == ival_WTHU_to_D_end
        assert ival_WWED.asfreq('D', 'S') == ival_WWED_to_D_start
        assert ival_WWED.asfreq('D', 'E') == ival_WWED_to_D_end
        assert ival_WTUE.asfreq('D', 'S') == ival_WTUE_to_D_start
        assert ival_WTUE.asfreq('D', 'E') == ival_WTUE_to_D_end
        assert ival_WMON.asfreq('D', 'S') == ival_WMON_to_D_start
        assert ival_WMON.asfreq('D', 'E') == ival_WMON_to_D_end

        assert ival_W.asfreq('H', 'S') == ival_W_to_H_start
        assert ival_W.asfreq('H', 'E') == ival_W_to_H_end
        assert ival_W.asfreq('Min', 'S') == ival_W_to_T_start
        assert ival_W.asfreq('Min', 'E') == ival_W_to_T_end
        assert ival_W.asfreq('S', 'S') == ival_W_to_S_start
        assert ival_W.asfreq('S', 'E') == ival_W_to_S_end
#.........这里部分代码省略.........
开发者ID:DusanMilunovic,项目名称:pandas,代码行数:101,代码来源:test_asfreq.py


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