- API reference
- pandas arrays, scalars, and data types
- pandas.array...
pandas.arrays.PeriodArray#
- classpandas.arrays.PeriodArray(values,dtype=None,freq=None,copy=False)[source]#
Pandas ExtensionArray for storing Period data.
Users should use
array()to create new instances.- Parameters:
- valuesUnion[PeriodArray, Series[period], ndarray[int], PeriodIndex]
The data to store. These should be arrays that can be directlyconverted to ordinals without inference or copy (PeriodArray,ndarray[int64]), or a box around such an array (Series[period],PeriodIndex).
- dtypePeriodDtype, optional
A PeriodDtype instance from which to extract afreq. If bothfreq anddtype are specified, then the frequencies must match.
- freqstr or DateOffset
Thefreq to use for the array. Mostly applicable whenvaluesis an ndarray of integers, whenfreq is required. Whenvaluesis a PeriodArray (or box around), it’s checked that
values.freqmatchesfreq.- copybool, default False
Whether to copy the ordinals before storing.
Attributes
None
Methods
None
See also
PeriodRepresents a period of time.
PeriodIndexImmutable Index for period data.
period_rangeCreate a fixed-frequency PeriodArray.
arrayConstruct a pandas array.
Notes
There are two components to a PeriodArray
ordinals : integer ndarray
freq : pd.tseries.offsets.Offset
The values are physically stored as a 1-D ndarray of integers. These arecalled “ordinals” and represent some kind of offset from a base.
Thefreq indicates the span covered by each element of the array.All elements in the PeriodArray have the samefreq.
Examples
>>>pd.arrays.PeriodArray(pd.PeriodIndex(['2023-01-01',...'2023-01-02'],freq='D'))<PeriodArray>['2023-01-01', '2023-01-02']Length: 2, dtype: period[D]