pandas.arrays.DatetimeArray

class pandas.arrays.DatetimeArray(values, dtype=dtype('<M8[ns]'), freq=None, copy=False)[source]

Pandas ExtensionArray for tz-naive or tz-aware datetime data.

New in version 0.24.0.

Warning

DatetimeArray is currently experimental, and its API may change without warning. In particular, DatetimeArray.dtype is expected to change to always be an instance of an ExtensionDtype subclass.

Parameters
valuesSeries, Index, DatetimeArray, ndarray

The datetime data.

For DatetimeArray values (or a Series or Index boxing one), dtype and freq will be extracted from values, with precedence given to

dtypenumpy.dtype or DatetimeTZDtype

Note that the only NumPy dtype allowed is ‘datetime64[ns]’.

freqstr or Offset, optional
copybool, default False

Whether to copy the underlying array of values.

Attributes

asi8

Integer representation of the values.

date

Returns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information).

day

The days of the datetime.

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.

dtype

The dtype for the DatetimeArray.

freq

Return the frequency object if it is set, otherwise None.

freqstr

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

hour

The hours of the datetime.

inferred_freq

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

is_leap_year

Boolean indicator if the date belongs to a leap year.

is_month_end

Indicates whether the date is the last day of the month.

is_month_start

Indicates whether the date is the first day of the month.

is_normalized

Returns True if all of the dates are at midnight (“no time”)

is_quarter_end

Indicator for whether the date is the last day of a quarter.

is_quarter_start

Indicator for whether the date is the first day of a quarter.

is_year_end

Indicate whether the date is the last day of the year.

is_year_start

Indicate whether the date is the first day of a year.

microsecond

The microseconds of the datetime.

minute

The minutes of the datetime.

month

The month as January=1, December=12.

nanosecond

The nanoseconds of the datetime.

nbytes

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

quarter

The quarter of the date.

resolution

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

second

The seconds of the datetime.

shape

Return a tuple of the array dimensions.

size

The number of elements in this array.

time

Returns numpy array of datetime.time.

timetz

Returns numpy array of datetime.time also containing timezone information.

tz

Return timezone, if any.

tzinfo

Alias for tz attribute

week

The week ordinal of the year.

weekday

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

weekday_name

(DEPRECATED) The name of day in a week (ex: Friday)

weekofyear

The week ordinal of the year.

year

The year of the datetime.

Methods

argsort(self[, ascending, kind])

Return the indices that would sort this array.

astype(self, dtype[, copy])

Cast to a NumPy array with ‘dtype’.

ceil(self, freq[, ambiguous, nonexistent])

Perform ceil operation on the data to the specified freq.

copy(self[, deep])

Return a copy of the array.

day_name(self[, locale])

Return the day names of the DateTimeIndex with specified locale.

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.

floor(self, freq[, ambiguous, nonexistent])

Perform floor operation on the data to the specified freq.

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.

month_name(self[, locale])

Return the month names of the DateTimeIndex with specified locale.

normalize(self)

Convert times to midnight.

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

Repeat elements of an array.

round(self, freq[, ambiguous, nonexistent])

Perform round operation on the data to the specified freq.

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_julian_date(self)

Convert Datetime Array to float64 ndarray of Julian Dates.

to_period(self[, freq])

Cast to PeriodArray/Index at a particular frequency.

to_perioddelta(self, freq)

Calculate TimedeltaArray of difference between index values and index converted to PeriodArray at specified freq.

to_pydatetime(self)

Return Datetime Array/Index as object ndarray of datetime.datetime objects

tz_convert(self, tz)

Convert tz-aware Datetime Array/Index from one time zone to another.

tz_localize(self, tz[, ambiguous, …])

Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/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