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)
Attempt to infer fall dst-transition hours based on order
name : object
Name to be stored in the index
Notes
To learn more about the frequency strings, please see this link.
Attributes
T
return the transpose, which is by definition self asi8
asobject
return object Index which contains boxed values base
return the base object if the memory of the underlying data is data
return the data pointer of the underlying data 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
dtype_str
flags
freq
get/set the frequncy of the Index freqstr
Return the frequency object as a string if its set, otherwise None has_duplicates
hasnans
hour
The hours of the datetime inferred_freq
inferred_type
is_all_dates
is_leap_year
Logical indicating if the date belongs to a leap year is_monotonic
alias for is_monotonic_increasing (deprecated) is_monotonic_decreasing
return if the index is monotonic decreasing (only equal or is_monotonic_increasing
return if the index is monotonic increasing (only equal or is_month_end
Logical indicating if last day of month (defined by frequency) is_month_start
Logical indicating if first day of month (defined by frequency) is_normalized
is_quarter_end
Logical indicating if last day of quarter (defined by frequency) is_quarter_start
Logical indicating if first day of quarter (defined by frequency) is_unique
is_year_end
Logical indicating if last day of year (defined by frequency) is_year_start
Logical indicating if first day of year (defined by frequency) itemsize
return the size of the dtype of the item of the underlying data microsecond
The microseconds of the datetime minute
The minutes of the datetime month
The month as January=1, December=12 name
names
nanosecond
The nanoseconds of the datetime nbytes
return the number of bytes in the underlying data ndim
return the number of dimensions of the underlying data, nlevels
offset
quarter
The quarter of the date resolution
second
The seconds of the datetime shape
return a tuple of the shape of the underlying data size
return the number of elements in the underlying data strides
return the strides of the underlying data time
Returns numpy array of datetime.time. tz
tzinfo
Alias for tz attribute values
return the underlying data as an ndarray week
The week ordinal of the year weekday
The day of the week with Monday=0, Sunday=6 weekday_name
The name of day in a week (ex: Friday) weekofyear
The week ordinal of the year year
The 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)floor the index to the specified freq 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
(\*args, \*\*kwargs)Return Index with duplicate values removed dropna
([how])Return Index without NA/NaN values duplicated
(\*args, \*\*kwargs)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)return an indexer suitable for taking from a non unique index get_level_values
(level)Return vector of label values for requested level, equal to the length 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 is
but that works through viewsis_boolean
()is_categorical
()is_floating
()is_integer
()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 item
()return the first element of the underlying data as a python join
(other[, how, level, return_indexers])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. nunique
([dropna])Return number of unique elements in the object. order
([return_indexer, ascending])Return sorted copy of Index 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
(key[, 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 str
alias of StringMethods
strftime
(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 sym_diff
(\*args, \*\*kwargs)symmetric_difference
(other[, result_name])Compute the symmetric difference of two Index objects. take
(indices[, axis, allow_fill, fill_value])return a new %(klass)s of the values selected by the indices to_datetime
([dayfirst])to_julian_date
()Convert DatetimeIndex to Float64Index of Julian Dates. to_native_types
([slicer])slice and dice then format 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
(\*args, \*\*kwargs)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 Index of 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.