pandas.arrays.PeriodArray

class pandas.arrays.PeriodArray(values, freq=None, dtype=None, copy=False)[source]

Pandas ExtensionArray for storing Period data.

Users should use period_array() to create new instances.

Parameters
valuesUnion[PeriodArray, Series[period], ndarray[int], PeriodIndex]

The data to store. These should be arrays that can be directly converted to ordinals without inference or copy (PeriodArray, ndarray[int64]), or a box around such an array (Series[period], PeriodIndex).

freqstr or DateOffset

The freq to use for the array. Mostly applicable when values is an ndarray of integers, when freq is required. When values is a PeriodArray (or box around), it’s checked that values.freq matches freq.

dtypePeriodDtype, optional

A PeriodDtype instance from which to extract a freq. If both freq and dtype are specified, then the frequencies must match.

copybool, default False

Whether to copy the ordinals before storing.

See also

period_array

Create a new PeriodArray.

PeriodIndex

Immutable Index for period data.

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 are called “ordinals” and represent some kind of offset from a base.

The freq indicates the span covered by each element of the array. All elements in the PeriodArray have the same freq.

Attributes

asi8

Integer representation of the values.

day

The days of the period

day_of_year

The ordinal day of the year

dayofweek

The day of the week with Monday=0, Sunday=6

dayofyear

The ordinal day of the year

days_in_month

The number of days in the month

daysinmonth

The number of days in the month

freq

Return the frequency object for this PeriodArray.

freqstr

Return the frequency object as a string if its set, otherwise None

hour

The hour of the period

inferred_freq

Tryies to return a string representing a frequency guess, generated by infer_freq.

is_leap_year

Logical indicating if the date belongs to a leap year

minute

The minute of the period

month

The month as January=1, December=12

nbytes

The number of bytes needed to store this object in memory.

ndim

Extension Arrays are only allowed to be 1-dimensional.

quarter

The quarter of the date

resolution

Returns day, hour, minute, second, millisecond or microsecond

second

The second of the period

shape

Return a tuple of the array dimensions.

size

The number of elements in this array.

week

The week ordinal of the year

weekday

The day of the week with Monday=0, Sunday=6

weekofyear

The week ordinal of the year

year

The year of the period

dtype

end_time

flags

qyear

start_time

Methods

argsort(self[, ascending, kind])

Return the indices that would sort this array.

asfreq(self[, freq, how])

Convert the Period Array/Index to the specified frequency freq.

astype(self, dtype[, copy])

Cast to a NumPy array with ‘dtype’.

copy(self[, deep])

Return a copy of the array.

dropna(self)

Return ExtensionArray without NA values

factorize(self, na_sentinel)

Encode the extension array as an enumerated type.

fillna(self[, value, method, limit])

Fill NA/NaN values using the specified method.

isna(self)

A 1-D array indicating if each value is missing.

max(self[, axis, skipna])

Return the maximum value of the Array or maximum along an axis.

min(self[, axis, skipna])

Return the minimum value of the Array or minimum along an axis.

repeat(self, repeats, \*args, \*\*kwargs)

Repeat elements of an array.

searchsorted(self, value[, side, sorter])

Find indices where elements should be inserted to maintain order.

shift(self, periods, fill_value)

Shift values by desired number.

strftime(self, date_format)

Convert to Index using specified date_format.

take(self, indices[, allow_fill, fill_value])

Take elements from an array.

to_timestamp(self[, freq, how])

Cast to DatetimeArray/Index.

unique(self)

Compute the ExtensionArray of unique values.

value_counts(self[, dropna])

Return a Series containing counts of unique values.

view(self[, dtype])

New view on this array with the same data.

map

Scroll To Top