pandas.DatetimeIndex
- class pandas.DatetimeIndex(data=None, freq=NoDefault.no_default, tz=None, normalize=False, closed=None, ambiguous='raise', dayfirst=False, yearfirst=False, dtype=None, copy=False, name=None)[source]
-
Immutable ndarray-like of datetime64 data.
Represented internally as int64, and which can be boxed to Timestamp objects that are subclasses of datetime and carry metadata.
- Parameters
-
- data:array-like (1-dimensional), optional
-
Optional datetime-like data to construct index with.
- freq:str or pandas offset object, optional
-
One of pandas date offset strings or corresponding objects. The string ‘infer’ can be passed in order to set the frequency of the index as the inferred frequency upon creation.
- tz:pytz.timezone or dateutil.tz.tzfile or datetime.tzinfo or str
-
Set the Timezone of the data.
- normalize:bool, default False
-
Normalize start/end dates to midnight before generating date range.
- closed:{‘left’, ‘right’}, optional
-
Set whether to include start and end that are on the boundary. The default includes boundary points on either end.
- ambiguous:‘infer’, bool-ndarray, ‘NaT’, default ‘raise’
-
When clocks moved backward due to DST, ambiguous times may arise. For example in Central European Time (UTC+01), when going from 03:00 DST to 02:00 non-DST, 02:30:00 local time occurs both at 00:30:00 UTC and at 01:30:00 UTC. In such a situation, the ambiguous parameter dictates how ambiguous times should be handled.
‘infer’ will attempt to infer fall dst-transition hours based on order
bool-ndarray where True signifies a DST time, False signifies a non-DST time (note that this flag is only applicable for ambiguous times)
‘NaT’ will return NaT where there are ambiguous times
‘raise’ will raise an AmbiguousTimeError if there are ambiguous times.
- dayfirst:bool, default False
-
If True, parse dates in data with the day first order.
- yearfirst:bool, default False
-
If True parse dates in data with the year first order.
- dtype:numpy.dtype or DatetimeTZDtype or str, default None
-
Note that the only NumPy dtype allowed is ‘datetime64[ns]’.
- copy:bool, default False
-
Make a copy of input ndarray.
- name:label, default None
-
Name to be stored in the index.
See also
Index
-
The base pandas Index type.
TimedeltaIndex
-
Index of timedelta64 data.
PeriodIndex
-
Index of Period data.
to_datetime
-
Convert argument to datetime.
date_range
-
Create a fixed-frequency DatetimeIndex.
Notes
To learn more about the frequency strings, please see this link.
Attributes
The year of the datetime.
The month as January=1, December=12.
The day of the datetime.
The hours of the datetime.
The minutes of the datetime.
The seconds of the datetime.
The microseconds of the datetime.
The nanoseconds of the datetime.
Returns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information).
Returns numpy array of datetime.time.
Returns numpy array of datetime.time also containing timezone information.
The ordinal day of the year.
The ordinal day of the year.
(DEPRECATED) The week ordinal of the year.
(DEPRECATED) The week ordinal of the year.
The day of the week with Monday=0, Sunday=6.
The day of the week with Monday=0, Sunday=6.
The day of the week with Monday=0, Sunday=6.
The quarter of the date.
Return timezone, if any.
Return the frequency object if it is set, otherwise None.
Return the frequency object as a string if its set, otherwise None.
Indicates whether the date is the first day of the month.
Indicates whether the date is the last day of the month.
Indicator for whether the date is the first day of a quarter.
Indicator for whether the date is the last day of a quarter.
Indicate whether the date is the first day of a year.
Indicate whether the date is the last day of the year.
Boolean indicator if the date belongs to a leap year.
Tries to return a string representing a frequency guess, generated by infer_freq.
Methods
normalize
(*args, **kwargs)Convert times to midnight.
strftime
(*args, **kwargs)Convert to Index using specified date_format.
snap
([freq])Snap time stamps to nearest occurring frequency.
tz_convert
(tz)Convert tz-aware Datetime Array/Index from one time zone to another.
tz_localize
(tz[, ambiguous, nonexistent])Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index.
round
(*args, **kwargs)Perform round operation on the data to the specified freq.
floor
(*args, **kwargs)Perform floor operation on the data to the specified freq.
ceil
(*args, **kwargs)Perform ceil operation on the data to the specified freq.
to_period
(*args, **kwargs)Cast to PeriodArray/Index at a particular frequency.
to_perioddelta
(freq)Calculate TimedeltaArray of difference between index values and index converted to PeriodArray at specified freq.
to_pydatetime
(*args, **kwargs)Return Datetime Array/Index as object ndarray of datetime.datetime objects.
to_series
([keep_tz, index, name])Create a Series with both index and values equal to the index keys useful with map for returning an indexer based on an index.
to_frame
([index, name])Create a DataFrame with a column containing the Index.
month_name
(*args, **kwargs)Return the month names of the DateTimeIndex with specified locale.
day_name
(*args, **kwargs)Return the day names of the DateTimeIndex with specified locale.
mean
(*args, **kwargs)Return the mean value of the Array.
std
© 2008–2021, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/1.3.4/reference/api/pandas.DatetimeIndex.html