pandas.Period() 对象的开始和结束时间是什么时候?参数 'freq' 在 Period 对象中起什么作用?

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

假设一个 Period 对象在 Pandas 中创建为 -

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

这个周期对象的起点和终点是什么?频率 M 如何影响那些起点和终点?其实这个频率在这里起到什么作用呢?

freq指定周期的长度,是日周期还是月周期?等等。例如,如果您传递日期 2021-03-21,频率 D

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

然后可以通过调用 start_timeend_time 属性

来知道周期何时开始和结束
period.start_time
>>> Timestamp('2021-03-21 00:00:00')
period.end_time
>>> Timestamp('2021-03-21 23:59:59.999999999')

现在,考虑整个三月,一个频率 M 是一个月度周期

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')