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

Parameters:
yearint, array, or Series, default None

Year for the PeriodIndex.

quarterint, array, or Series, default None

Quarter for the PeriodIndex.

monthint, array, or Series, default None

Month for the PeriodIndex.

dayint, array, or Series, default None

Day for the PeriodIndex.

hourint, array, or Series, default None

Hour for the PeriodIndex.

minuteint, array, or Series, default None

Minute for the PeriodIndex.

secondint, array, or Series, 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.

Examples

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