Table Of Contents

Search

Enter search terms or a module, class or function name.

pandas.DatetimeIndex

class pandas.DatetimeIndex[source]

Immutable ndarray of datetime64 data, represented internally as int64, and which can be boxed to Timestamp objects that are subclasses of datetime and carry metadata such as frequency information.

Parameters:

data : array-like (1-dimensional), optional

Optional datetime-like data to construct index with

copy : bool

Make a copy of input ndarray

freq : string or pandas offset object, optional

One of pandas date offset strings or corresponding objects

start : starting value, datetime-like, optional

If data is None, start is used as the start point in generating regular timestamp data.

periods : int, optional, > 0

Number of periods to generate, if generating index. Takes precedence over end argument

end : end time, datetime-like, optional

If periods is none, generated index will extend to first conforming time on or just past end argument

closed : string or None, default None

Make the interval closed with respect to the given frequency to the ‘left’, ‘right’, or both sides (None)

tz : pytz.timezone or dateutil.tz.tzfile

ambiguous : ‘infer’, bool-ndarray, ‘NaT’, default ‘raise’

  • ‘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

infer_dst : boolean, default False

Deprecated since version 0.15.0: Attempt to infer fall dst-transition hours based on order

name : object

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

Notes

To learn more about the frequency strings, please see this link.

Attributes

year The year of the datetime
month The month as January=1, December=12
day The days of the datetime
hour The hours of the datetime
minute The minutes of the datetime
second The seconds of the datetime
microsecond The microseconds of the datetime
nanosecond The nanoseconds of the datetime
date Returns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information).
time Returns numpy array of datetime.time.
dayofyear The ordinal day of the year
weekofyear The week ordinal of the year
week The week ordinal of the year
dayofweek The day of the week with Monday=0, Sunday=6
weekday The day of the week with Monday=0, Sunday=6
weekday_name The name of day in a week (ex: Friday)
quarter The quarter of the date
tz
freq get/set the frequency of the Index
freqstr Return the frequency object as a string if its set, otherwise None
is_month_start Logical indicating if first day of month (defined by frequency)
is_month_end Logical indicating if last day of month (defined by frequency)
is_quarter_start Logical indicating if first day of quarter (defined by frequency)
is_quarter_end Logical indicating if last day of quarter (defined by frequency)
is_year_start Logical indicating if first day of year (defined by frequency)
is_year_end Logical indicating if last day of year (defined by frequency)
is_leap_year Logical indicating if the date belongs to a leap year
inferred_freq

Methods

normalize() Return DatetimeIndex with times to midnight.
strftime(date_format) Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library.
snap([freq]) Snap time stamps to nearest occurring frequency
tz_convert(tz) Convert tz-aware DatetimeIndex from one time zone to another (using
tz_localize(tz[, ambiguous, errors]) Localize tz-naive DatetimeIndex to given time zone (using
round(freq, *args, **kwargs) round the index to the specified freq
floor(freq) floor the index to the specified freq
ceil(freq) ceil the index to the specified freq
to_period([freq]) Cast to PeriodIndex at a particular frequency
to_perioddelta(freq) Calculates TimedeltaIndex of difference between index values and index converted to PeriodIndex at specified freq.
to_pydatetime() Return DatetimeIndex as object ndarray of datetime.datetime objects
to_series([keep_tz]) Create a Series with both index and values equal to the index keys
to_frame([index]) Create a DataFrame with a column containing the Index.
Scroll To Top