Skip to main content
`Ctrl`+`K`

# pandas.PeriodIndex.from_fields

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

  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 array-like. The frequency is inferred from the fields provided or can be given explicitly.

  Parameters:
    year int, array, or Series, default None

      Year for the PeriodIndex.

    quarter int, array, or Series, default None

      Quarter for the PeriodIndex.

    month int, array, or Series, default None

      Month for the PeriodIndex.

    day int, array, or Series, default None

      Day for the PeriodIndex.

    hour int, array, or Series, default None

      Hour for the PeriodIndex.

    minute int, array, or Series, default None

      Minute for the PeriodIndex.

    second int, array, or Series, default None

      Second for the PeriodIndex.

    freq str 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]')