Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the start and end times of a pandas.Period() object? What role does the parameter 'freq' play in the Period object?

Suppose a Period object is created in Pandas as -

In [1]: pd.Period('2021', 'M')
Out [1]: Period('2021-01', 'M')

What are the start and end points of this period object? How does the frequency M affect those start and end points? In fact, what role does this frequency play here?

like image 431
Anirban Chakraborty Avatar asked Dec 07 '25 03:12

Anirban Chakraborty


1 Answers

The freq specifies the length of the period, is it a daily period or monthly period? etc.. For example if you pass a date 2021-03-21 with a D frequency

import pandas as pd
period = pd.Period('2021-03-21', 'D')

then one can know when does the period starts and end by calling the the start_time and end_time attributes

period.start_time
>>> Timestamp('2021-03-21 00:00:00')
period.end_time
>>> Timestamp('2021-03-21 23:59:59.999999999')

Now, consider the whole month of March, a frequency M is a Monthly period

period = pd.Period('2021-03-21', 'M')
period.start_time
>>> Timestamp('2021-03-01 00:00:00')
period.end_time
>>> Timestamp('2021-03-31 23:59:59.999999999')
like image 96
Miguel Trejo Avatar answered Dec 08 '25 15:12

Miguel Trejo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!