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
Treturn the transpose, which is by definition self asi8asobjectreturn object Index which contains boxed values basereturn the base object if the memory of the underlying data is datareturn the data pointer of the underlying data dateReturns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information). dayThe days of the datetime dayofweekThe day of the week with Monday=0, Sunday=6 dayofyearThe ordinal day of the year days_in_monthThe number of days in the month daysinmonthThe number of days in the month dtypedtype_stremptyflagsfreqget/set the frequency of the Index freqstrReturn the frequency object as a string if its set, otherwise None has_duplicateshasnanshourThe hours of the datetime inferred_freqinferred_typeis_all_datesis_leap_yearLogical indicating if the date belongs to a leap year is_monotonicalias for is_monotonic_increasing (deprecated) is_monotonic_decreasingreturn if the index is monotonic decreasing (only equal or is_monotonic_increasingreturn if the index is monotonic increasing (only equal or is_month_endLogical indicating if last day of month (defined by frequency) is_month_startLogical indicating if first day of month (defined by frequency) is_normalizedis_quarter_endLogical indicating if last day of quarter (defined by frequency) is_quarter_startLogical indicating if first day of quarter (defined by frequency) is_uniqueis_year_endLogical indicating if last day of year (defined by frequency) is_year_startLogical indicating if first day of year (defined by frequency) itemsizereturn the size of the dtype of the item of the underlying data microsecondThe microseconds of the datetime minuteThe minutes of the datetime monthThe month as January=1, December=12 namenamesnanosecondThe nanoseconds of the datetime nbytesreturn the number of bytes in the underlying data ndimreturn the number of dimensions of the underlying data, nlevelsoffsetquarterThe quarter of the date resolutionsecondThe seconds of the datetime shapereturn a tuple of the shape of the underlying data sizereturn the number of elements in the underlying data stridesreturn the strides of the underlying data timeReturns numpy array of datetime.time. tztzinfoAlias for tz attribute valuesreturn the underlying data as an ndarray weekThe week ordinal of the year weekdayThe day of the week with Monday=0, Sunday=6 weekday_nameThe name of day in a week (ex: Friday) weekofyearThe week ordinal of the year yearThe year of the datetime Methods
all([other])any([other])append(other)Append a collection of Index options together argmax([axis])Returns the indices of the maximum values along an axis. argmin([axis])Returns the indices of the minimum values along an axis. argsort(*args, **kwargs)Returns the indices that would sort the index and its underlying data. asof(label)For a sorted index, return the most recent label up to and including the passed label. asof_locs(where, mask)where : array of timestamps astype(dtype[, copy])Create an Index with values cast to dtypes. ceil(freq)ceil the index to the specified freq contains(key)return a boolean if this key is IN the index copy([name, deep, dtype])Make a copy of this object. delete(loc)Make a new DatetimeIndex with passed location(s) deleted. difference(other)Return a new Index with elements from the index that are not in other. drop(labels[, errors])Make new Index with passed list of labels deleted drop_duplicates([keep])Return Index with duplicate values removed dropna([how])Return Index without NA/NaN values duplicated([keep])Return boolean np.ndarray denoting duplicate values equals(other)Determines if two Index objects contain the same elements. factorize([sort, na_sentinel])Encode the object as an enumerated type or categorical variable fillna([value, downcast])Fill NA/NaN values with the specified value floor(freq)floor the index to the specified freq format([name, formatter])Render a string representation of the Index get_duplicates()get_indexer(target[, method, limit, tolerance])Compute indexer and mask for new index given the current index. get_indexer_for(target, **kwargs)guaranteed return of an indexer even when non-unique get_indexer_non_unique(target)Compute indexer and mask for new index given the current index. get_level_values(level)Return an Index of values for requested level, equal to the length of the index. get_loc(key[, method, tolerance])Get integer location for requested label get_slice_bound(label, side, kind)Calculate slice bound that corresponds to given label. get_value(series, key)Fast lookup of value from 1-dimensional ndarray. get_value_maybe_box(series, key)get_values()return the underlying data as an ndarray groupby(values)Group the index labels by a given array of values. holds_integer()identical(other)Similar to equals, but check that other comparable attributes are indexer_at_time(time[, asof])Select values at particular time of day (e.g. indexer_between_time(start_time, end_time[, ...])Select values between particular times of day (e.g., 9:00-9:30AM). insert(loc, item)Make new Index inserting new item at location intersection(other)Specialized intersection for DatetimeIndex objects. is_(other)More flexible, faster check like isbut that works through viewsis_boolean()is_categorical()is_floating()is_integer()is_interval()is_lexsorted_for_tuple(tup)is_mixed()is_numeric()is_object()is_type_compatible(typ)isin(values)Compute boolean array of whether each index value is found in the isna()Detect missing values isnull()Detect missing values item()return the first element of the underlying data as a python join(other[, how, level, return_indexers, sort])See Index.join map(f)max([axis])Return the maximum value of the Index or maximum along an axis. memory_usage([deep])Memory usage of my values min([axis])Return the minimum value of the Index or minimum along an axis. normalize()Return DatetimeIndex with times to midnight. notna()Inverse of isna notnull()Inverse of isna nunique([dropna])Return number of unique elements in the object. putmask(mask, value)return a new Index of the values set with the mask ravel([order])return an ndarray of the flattened values of the underlying data reindex(target[, method, level, limit, ...])Create index with target’s values (move/add/delete values as necessary) rename(name[, inplace])Set new names on index. repeat(repeats, *args, **kwargs)Analogous to ndarray.repeat reshape(*args, **kwargs)NOT IMPLEMENTED: do not call this method, as reshaping is not supported for Index objects and will raise an error. round(freq, *args, **kwargs)round the index to the specified freq searchsorted(value[, side, sorter])Find indices where elements should be inserted to maintain order. set_names(names[, level, inplace])Set new names on index. set_value(arr, key, value)Fast lookup of value from 1-dimensional ndarray. shift(n[, freq])Specialized shift which produces a DatetimeIndex slice_indexer([start, end, step, kind])Return indexer for specified label slice. slice_locs([start, end, step, kind])Compute slice locations for input labels. snap([freq])Snap time stamps to nearest occurring frequency sort(*args, **kwargs)sort_values([return_indexer, ascending])Return sorted copy of Index sortlevel([level, ascending, sort_remaining])For internal compatibility with with the Index API stralias of StringMethodsstrftime(date_format)Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library. summary([name])return a summarized representation symmetric_difference(other[, result_name])Compute the symmetric difference of two Index objects. take(indices[, axis, allow_fill, fill_value])return a new Index of the values selected by the indices to_datetime([dayfirst])to_frame([index])Create a DataFrame with a column containing the Index. to_julian_date()Convert DatetimeIndex to Float64Index of Julian Dates. to_native_types([slicer])Format specified values of self and return them. to_period([freq])Cast to PeriodIndex at a particular frequency to_perioddelta(freq)Calcuates 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 tolist()return a list of the underlying data transpose(*args, **kwargs)return the transpose, which is by definition self 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 union(other)Specialized union for DatetimeIndex objects. union_many(others)A bit of a hack to accelerate unioning a collection of indexes unique()Return unique values in the object. value_counts([normalize, sort, ascending, ...])Returns object containing counts of unique values. view([cls])where(cond[, other])New in version 0.19.0.