"Data analysis using Python" reading notes--tenth Chapter time series (II.)

Source: Internet
Author: User

5. Period and its arithmetic operation

The period (period) represents a time interval, such as days, months, seasons, years, etc. The period class represents this data type, and its constructors need to use a string or integer, as well as a frequency.

#-*-coding:utf-8-*-ImportNumPy as NPImportPandas as PDImportMatplotlib.pyplot as PltImportdatetime as DT fromPandasImportSeries,dataframe fromDatetimeImportdatetime fromDateutil.parserImportParseImport Time fromPandas.tseries.offsetsImportHour,minute,day,monthendImportPytz#the following ' A-dec ' is the last calendar day of the end of the year Decemberp = PD. Period (' .', freq ='A-dec')#period can be directly added and reducedPrintP + 5#period of the same frequency can be added and reduced, and different frequencies cannot be added or reduced.RNG = PD. Period (' -', freq ='A-dec') -PPrintrngrng= Pd.period_range ('1/1/2000','6/30/2000', freq ='M')#The type is <class ' Pandas.tseries.period.PeriodIndex ', which is formally an array of arrays#Note that the following form is not the form of the book, but the float type, but when indexed, the date formPrintrngPrinttype (RNG)PrintSeries (NP.RANDOM.RANDN (6), index = RNG),'\ n'#the constructors of the Periodindex class also allow direct use of a set of stringsvalues = ['2001q3','2002Q2','2003q1']index= PD. Periodindex (Values,freq ='Q-dec')#the following indexPrintIndex
>>>
2021
-1
Array ([361, 362, 363, 364, 365], Dtype=int64)
<class ' Pandas.tseries.period.PeriodIndex ' >
2000-01-0.504031
2000-02 1.345024
2000-03 0.074367
2000-04-1.152187
2000-05-0.460272
2000-06 0.486135

Array ([126, 129, PPI], Dtype=int64)
[Finished in 1.4s]

"Data analysis using Python" reading notes--tenth Chapter time series (II.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.