Construct a PeriodIndex from ordinals. Parameters ---------- ordinals : array-like of int The period offsets from the proleptic Gregorian epoch. freq : str or period object One of pandas period strings or corresponding objects.
(cls, ordinals, *, freq, name=None)
| 320 | |
| 321 | @classmethod |
| 322 | def from_ordinals(cls, ordinals, *, freq, name=None) -> Self: |
| 323 | """ |
| 324 | Construct a PeriodIndex from ordinals. |
| 325 | |
| 326 | Parameters |
| 327 | ---------- |
| 328 | ordinals : array-like of int |
| 329 | The period offsets from the proleptic Gregorian epoch. |
| 330 | freq : str or period object |
| 331 | One of pandas period strings or corresponding objects. |
| 332 | name : str, default None |
| 333 | Name of the resulting PeriodIndex. |
| 334 | |
| 335 | Returns |
| 336 | ------- |
| 337 | PeriodIndex |
| 338 | |
| 339 | See Also |
| 340 | -------- |
| 341 | PeriodIndex.from_fields : Construct a PeriodIndex from fields |
| 342 | (year, month, day, etc.). |
| 343 | PeriodIndex.to_timestamp : Cast to DatetimeArray/Index. |
| 344 | |
| 345 | Examples |
| 346 | -------- |
| 347 | >>> idx = pd.PeriodIndex.from_ordinals([-1, 0, 1], freq="Q") |
| 348 | >>> idx |
| 349 | PeriodIndex(['1969Q4', '1970Q1', '1970Q2'], dtype='period[Q-DEC]') |
| 350 | """ |
| 351 | ordinals = np.asarray(ordinals, dtype=np.int64) |
| 352 | dtype = PeriodDtype(freq) |
| 353 | data = PeriodArray._simple_new(ordinals, dtype=dtype) |
| 354 | return cls._simple_new(data, name=name) |
| 355 | |
| 356 | # ------------------------------------------------------------------------ |
| 357 | # Data |