October 2019
Beginner to intermediate
674 pages
16h 43m
English
The Period datatype is used to represent a range or span of time. Here are a few examples:
# Period representing May 2014
In [287]: pd.Period('2014', freq='A-MAY')
Out[287]: Period('2014', 'A-MAY')
# Period representing specific day - June 11, 2014
In [292]: pd.Period('06/11/2014')
Out[292]: Period('2014-06-11', 'D')
# Period representing 11AM, Nov 11, 1918
In [298]: pd.Period('11/11/1918 11:00',freq='H')
Out[298]: Period('1918-11-11 11:00', 'H')
We can add integers to the Period datatypes to advance the period by the requisite number of frequency units:
In [299]: pd.Period('06/30/2014')+4 Out[299]: Period('2014-07-04', 'D') In [303]: pd.Period('11/11/1918 11:00',freq='H') - 48 Out[303]: Period('1918-11-09 11:00', ...Read now
Unlock full access