pandas.PeriodIndex.from_fields#

classmethod PeriodIndex.from_fields(*, year=None, quarter=None, month=None, day=None, hour=None, minute=None, second=None, freq=None)[source]#

Construct a PeriodIndex from fields (year, month, day, etc.).

Each field (year, quarter, month, day, hour, minute, second) can be specified as a scalar or list-like. At least one field must be list-like; scalar fields are broadcast to its length. The frequency is inferred from the fields provided or can be given explicitly.

Parameters:
yearint or list-like, default None

Year for the PeriodIndex.

quarterint or list-like, default None

Quarter for the PeriodIndex.

monthint or list-like, default None

Month for the PeriodIndex.

dayint or list-like, default None

Day for the PeriodIndex.

hourint or list-like, default None

Hour for the PeriodIndex.

minuteint or list-like, default None

Minute for the PeriodIndex.

secondint or list-like, default None

Second for the PeriodIndex.

freqstr or period object, optional

One of pandas period strings or corresponding objects.

Returns:
PeriodIndex

See also

PeriodIndex.from_ordinals

Construct a PeriodIndex from ordinals.

PeriodIndex.to_timestamp

Cast to DatetimeArray/Index.

Notes

A list-like field must be a list, tuple, np.ndarray, or Series. Other array-like inputs, such as a range or an Index, are not accepted.

Examples

>>> idx = pd.PeriodIndex.from_fields(year=[2000, 2002], quarter=[1, 3])
>>> idx
PeriodIndex(['2000Q1', '2002Q3'], dtype='period[Q-DEC]')