pandas.PeriodIndex¶
-
class
pandas.
PeriodIndex
(data=None, ordinal=None, freq=None, start=None, end=None, periods=None, tz=None, dtype=None, copy=False, name=None, **fields)[source]¶ Immutable ndarray holding ordinal values indicating regular periods in time such as particular years, quarters, months, etc.
Index keys are boxed to Period objects which carries the metadata (eg, frequency information).
- Parameters
- dataarray-like (1d integer np.ndarray or PeriodArray), optional
Optional period-like data to construct index with
- copybool
Make a copy of input ndarray
- freqstring or period object, optional
One of pandas period strings or corresponding objects
- startstarting value, period-like, optional
If data is None, used as the start point in generating regular period data.
Deprecated since version 0.24.0.
- periodsint, optional, > 0
Number of periods to generate, if generating index. Takes precedence over end argument
Deprecated since version 0.24.0.
- endend value, period-like, optional
If periods is none, generated index will extend to first conforming period on or just past end argument
Deprecated since version 0.24.0.
- yearint, array, or Series, default None
- monthint, array, or Series, default None
- quarterint, array, or Series, default None
- dayint, array, or Series, default None
- hourint, array, or Series, default None
- minuteint, array, or Series, default None
- secondint, array, or Series, default None
- tzobject, default None
Timezone for converting datetime64 data to Periods
- dtypestr or PeriodDtype, default None
See also
Index
The base pandas Index type.
Period
Represents a period of time.
DatetimeIndex
Index with datetime64 data.
TimedeltaIndex
Index of timedelta64 data.
period_range
Create a fixed-frequency PeriodIndex.
Notes
Creating a PeriodIndex based on start, periods, and end has been deprecated in favor of
period_range()
.Examples
>>> idx = pd.PeriodIndex(year=year_arr, quarter=q_arr)
Attributes
The days of the period
The day of the week with Monday=0, Sunday=6
The ordinal day of the year
The number of days in the month
The number of days in the month
Return the frequency object if it is set, otherwise None.
Return the frequency object as a string if it is set, otherwise None.
The hour of the period
Logical indicating if the date belongs to a leap year
The minute of the period
The month as January=1, December=12
The quarter of the date
The second of the period
The week ordinal of the year
The day of the week with Monday=0, Sunday=6
The week ordinal of the year
The year of the period
end_time
qyear
start_time
Methods
asfreq
(*args, **kwargs)Convert the Period Array/Index to the specified frequency freq.
strftime
(*args, **kwargs)Convert to Index using specified date_format.
to_timestamp
(*args, **kwargs)Cast to DatetimeArray/Index.