3

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anirban Chakraborty
  • 539
  • 1
  • 5
  • 15
  • it is fully documented... https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Period.html – Rob Raymond Mar 15 '21 at 23:38
  • 1
    To be fair, that documentation does not really explain what is meant by 'frequency'. Normally, a perdiod of time has a duration, and frequency is the inverse of the duration. – Erik Jul 23 '21 at 12:02

1 Answers1

2

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')
Miguel Trejo
  • 5,913
  • 5
  • 24
  • 49