Index objects

Index

Many of these methods or variants thereof are available on the objectsthat contain an index (Series/DataFrame) and those should most likely beused before calling these methods directly.

IndexImmutable ndarray implementing an ordered, sliceable set.

Properties

Index.valuesReturn an array representing the data in the Index.
Index.is_monotonicAlias for is_monotonic_increasing.
Index.is_monotonic_increasingReturn if the index is monotonic increasing (only equal or increasing) values.
Index.is_monotonic_decreasingReturn if the index is monotonic decreasing (only equal or decreasing) values.
Index.is_uniqueReturn if the index has unique values.
Index.has_duplicates
Index.hasnansReturn if I have any nans; enables various perf speedups.
Index.dtypeReturn the dtype object of the underlying data.
Index.dtype_str(DEPRECATED) Return the dtype str of the underlying data.
Index.inferred_typeReturn a string of the type inferred from the values.
Index.is_all_dates
Index.shapeReturn a tuple of the shape of the underlying data.
Index.name
Index.names
Index.nbytesReturn the number of bytes in the underlying data.
Index.ndimNumber of dimensions of the underlying data, by definition 1.
Index.sizeReturn the number of elements in the underlying data.
Index.empty
Index.strides(DEPRECATED) Return the strides of the underlying data.
Index.itemsize(DEPRECATED) Return the size of the dtype of the item of the underlying data.
Index.base(DEPRECATED) Return the base object if the memory of the underlying data is shared.
Index.TReturn the transpose, which is by
Index.memory_usage(self[, deep])Memory usage of the values

Modifying and computations

Index.all(self, *args, **kwargs)Return whether all elements are True.
Index.any(self, *args, **kwargs)Return whether any element is True.
Index.argmin(self[, axis, skipna])Return a ndarray of the minimum argument indexer.
Index.argmax(self[, axis, skipna])Return an ndarray of the maximum argument indexer.
Index.copy(self[, name, deep, dtype])Make a copy of this object.
Index.delete(self, loc)Make new Index with passed location(-s) deleted.
Index.drop(self, labels[, errors])Make new Index with passed list of labels deleted.
Index.drop_duplicates(self[, keep])Return Index with duplicate values removed.
Index.duplicated(self[, keep])Indicate duplicate index values.
Index.equals(self, other)Determine if two Index objects contain the same elements.
Index.factorize(self[, sort, nasentinel])Encode the object as an enumerated type or categorical variable.
Index.identical(self, other)Similar to equals, but check that other comparable attributes are also equal.
Index.insert(self, loc, item)Make new Index inserting new item at location.
[Index.is](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.is_.html#pandas.Index.is_)(self, other)More flexible, faster check like is but that works through views.
Index.is_boolean(self)
Index.is_categorical(self)Check if the Index holds categorical data.
Index.is_floating(self)
Index.is_integer(self)
Index.is_interval(self)
Index.is_mixed(self)
Index.is_numeric(self)
Index.is_object(self)
Index.min(self[, axis, skipna])Return the minimum value of the Index.
Index.max(self[, axis, skipna])Return the maximum value of the Index.
Index.reindex(self, target[, method, level, …])Create index with target’s values (move/add/delete values as necessary).
Index.rename(self, name[, inplace])Alter Index or MultiIndex name.
Index.repeat(self, repeats[, axis])Repeat elements of a Index.
Index.where(self, cond[, other])Return an Index of same shape as self and whose corresponding entries are from self where cond is True and otherwise are from other.
Index.take(self, indices[, axis, …])Return a new Index of the values selected by the indices.
Index.putmask(self, mask, value)Return a new Index of the values set with the mask.
Index.unique(self[, level])Return unique values in the index.
Index.nunique(self[, dropna])Return number of unique elements in the object.
Index.value_counts(self[, normalize, sort, …])Return a Series containing counts of unique values.

Compatibility with MultiIndex

Index.set_names(self, names[, level, inplace])Set Index or MultiIndex name.
Index.is_lexsorted_for_tuple(self, tup)
Index.droplevel(self[, level])Return index with requested level(s) removed.

Missing values

Index.fillna(self[, value, downcast])Fill NA/NaN values with the specified value
Index.dropna(self[, how])Return Index without NA/NaN values
Index.isna(self)Detect missing values.
Index.notna(self)Detect existing (non-missing) values.

Conversion

Index.astype(self, dtype[, copy])Create an Index with values cast to dtypes.
Index.item(self)Return the first element of the underlying data as a python scalar.
Index.map(self, mapper[, naaction])Map values using input correspondence (a dict, Series, or function).
Index.ravel(self[, order])Return an ndarray of the flattened values of the underlying data.
Index.to_list(self)Return a list of the values.
Index.to_native_types(self[, slicer])Format specified values of _self and return them.
Index.to_series(self[, 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.
Index.to_frame(self[, index, name])Create a DataFrame with a column containing the Index.
Index.view(self[, cls])

Sorting

Index.argsort(self, *args, **kwargs)Return the integer indices that would sort the index.
Index.searchsorted(self, value[, side, sorter])Find indices where elements should be inserted to maintain order.
Index.sort_values(self[, return_indexer, …])Return a sorted copy of the index.

Time-specific operations

Index.shift(self[, periods, freq])Shift index by desired number of time frequency increments.

Combining / joining / set operations

Index.append(self, other)Append a collection of Index options together.
Index.join(self, other[, how, level, …])Compute joinindex and indexers to conform data structures to the new index.
Index.intersection(self, other[, sort])Form the intersection of two Index objects.
Index.union(self, other[, sort])Form the union of two Index objects.
Index.difference(self, other[, sort])Return a new Index with elements from the index that are not in _other.
Index.symmetric_difference(self, other[, …])Compute the symmetric difference of two Index objects.

Selecting

Index.asof(self, label)Return the label from the index, or, if not present, the previous one.
Index.asof_locs(self, where, mask)Find the locations (indices) of the labels from the index for every entry in the where argument.
Index.contains(self, key)(DEPRECATED) Return a boolean indicating whether the provided key is in the index.
Index.get_duplicates(self)(DEPRECATED) Extract duplicated index elements.
Index.get_indexer(self, target[, method, …])Compute indexer and mask for new index given the current index.
Index.get_indexer_for(self, target, **kwargs)Guaranteed return of an indexer even when non-unique.
Index.get_indexer_non_unique(self, target)Compute indexer and mask for new index given the current index.
Index.get_level_values(self, level)Return an Index of values for requested level.
Index.get_loc(self, key[, method, tolerance])Get integer location, slice or boolean mask for requested label.
Index.get_slice_bound(self, label, side, kind)Calculate slice bound that corresponds to given label.
Index.get_value(self, series, key)Fast lookup of value from 1-dimensional ndarray.
Index.get_values(self)(DEPRECATED) Return Index data as an numpy.ndarray.
Index.set_value(self, arr, key, value)Fast lookup of value from 1-dimensional ndarray.
Index.isin(self, values[, level])Return a boolean array where the index values are in values.
Index.slice_indexer(self[, start, end, …])For an ordered or unique index, compute the slice indexer for input labels and step.
Index.slice_locs(self[, start, end, step, kind])Compute slice locations for input labels.

Numeric Index

RangeIndexImmutable Index implementing a monotonic integer range.
Int64IndexImmutable ndarray implementing an ordered, sliceable set.
UInt64IndexImmutable ndarray implementing an ordered, sliceable set.
Float64IndexImmutable ndarray implementing an ordered, sliceable set.
RangeIndex.startThe value of the start parameter (0 if this was not supplied)
RangeIndex.stopThe value of the stop parameter
RangeIndex.stepThe value of the step parameter (1 if this was not supplied)
RangeIndex.from_range(data[, name, dtype])Create RangeIndex from a range object.

CategoricalIndex

CategoricalIndexIndex based on an underlying Categorical.

Categorical components

CategoricalIndex.codes
CategoricalIndex.categories
CategoricalIndex.ordered
CategoricalIndex.rename_categories(self, …)Rename categories.
CategoricalIndex.reorder_categories(self, …)Reorder categories as specified in new_categories.
CategoricalIndex.add_categories(self, …)Add new categories.
CategoricalIndex.remove_categories(self, …)Remove the specified categories.
CategoricalIndex.remove_unused_categories(…)Remove categories which are not used.
CategoricalIndex.set_categories(self, …)Set the categories to the specified new_categories.
CategoricalIndex.as_ordered(self, *args, …)Set the Categorical to be ordered.
CategoricalIndex.as_unordered(self, *args, …)Set the Categorical to be unordered.

Modifying and computations

CategoricalIndex.map(self, mapper)Map values using input correspondence (a dict, Series, or function).
CategoricalIndex.equals(self, other)Determine if two CategoricalIndex objects contain the same elements.

IntervalIndex

IntervalIndexImmutable index of intervals that are closed on the same side.

IntervalIndex components

IntervalIndex.from_arrays(left, right[, …])Construct from two arrays defining the left and right bounds.
IntervalIndex.from_tuples(data[, closed, …])Construct an IntervalIndex from an array-like of tuples
IntervalIndex.from_breaks(breaks[, closed, …])Construct an IntervalIndex from an array of splits.
IntervalIndex.leftReturn the left endpoints of each Interval in the IntervalIndex as an Index
IntervalIndex.rightReturn the right endpoints of each Interval in the IntervalIndex as an Index
IntervalIndex.midReturn the midpoint of each Interval in the IntervalIndex as an Index
IntervalIndex.closedWhether the intervals are closed on the left-side, right-side, both or neither
IntervalIndex.lengthReturn an Index with entries denoting the length of each Interval in the IntervalIndex
IntervalIndex.valuesReturn the IntervalIndex’s data as an IntervalArray.
IntervalIndex.is_emptyIndicates if an interval is empty, meaning it contains no points.
IntervalIndex.is_non_overlapping_monotonicReturn True if the IntervalIndex is non-overlapping (no Intervals share points) and is either monotonic increasing or monotonic decreasing, else False
IntervalIndex.is_overlappingReturn True if the IntervalIndex has overlapping intervals, else False.
IntervalIndex.get_loc(self, key, method, …)Get integer location, slice or boolean mask for requested label.
IntervalIndex.get_indexer(self, target, …)Compute indexer and mask for new index given the current index.
IntervalIndex.set_closed(self, closed)Return an IntervalIndex identical to the current one, but closed on the specified side
IntervalIndex.contains(self, other)Check elementwise if the Intervals contain the value.
IntervalIndex.overlaps(self, other)Check elementwise if an Interval overlaps the values in the IntervalIndex.
IntervalIndex.to_tuples(self[, na_tuple])Return an Index of tuples of the form (left, right)

MultiIndex

MultiIndexA multi-level, or hierarchical, index object for pandas objects.
IndexSliceCreate an object to more easily perform multi-index slicing

MultiIndex constructors

MultiIndex.from_arrays(arrays[, sortorder, …])Convert arrays to MultiIndex.
MultiIndex.from_tuples(tuples[, sortorder, …])Convert list of tuples to MultiIndex.
MultiIndex.from_product(iterables[, …])Make a MultiIndex from the cartesian product of multiple iterables.
MultiIndex.from_frame(df[, sortorder, names])Make a MultiIndex from a DataFrame.

MultiIndex properties

MultiIndex.namesNames of levels in MultiIndex
MultiIndex.levels
MultiIndex.codes
MultiIndex.nlevelsInteger number of levels in this MultiIndex.
MultiIndex.levshapeA tuple with the length of each level.

MultiIndex components

MultiIndex.set_levels(self, levels[, level, …])Set new levels on MultiIndex.
MultiIndex.set_codes(self, codes[, level, …])Set new codes on MultiIndex.
MultiIndex.to_hierarchical(self, n_repeat[, …])(DEPRECATED) Return a MultiIndex reshaped to conform to the shapes given by n_repeat and n_shuffle.
MultiIndex.to_flat_index(self)Convert a MultiIndex to an Index of Tuples containing the level values.
MultiIndex.to_frame(self[, index, name])Create a DataFrame with the levels of the MultiIndex as columns.
MultiIndex.is_lexsorted(self)Return True if the codes are lexicographically sorted
MultiIndex.sortlevel(self[, level, …])Sort MultiIndex at the requested level.
MultiIndex.droplevel(self[, level])Return index with requested level(s) removed.
MultiIndex.swaplevel(self[, i, j])Swap level i with level j.
MultiIndex.reorder_levels(self, order)Rearrange levels using input order.
MultiIndex.remove_unused_levels(self)Create a new MultiIndex from the current that removes unused levels, meaning that they are not expressed in the labels.

MultiIndex selecting

MultiIndex.get_loc(self, key[, method])Get location for a label or a tuple of labels as an integer, slice or boolean mask.
MultiIndex.get_loc_level(self, key[, level, …])Get both the location for the requested label(s) and the resulting sliced index.
MultiIndex.get_indexer(self, target[, …])Compute indexer and mask for new index given the current index.
MultiIndex.get_level_values(self, level)Return vector of label values for requested level, equal to the length of the index.

DatetimeIndex

DatetimeIndexImmutable 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.

Time/Date components

DatetimeIndex.yearThe year of the datetime.
DatetimeIndex.monthThe month as January=1, December=12.
DatetimeIndex.dayThe days of the datetime.
DatetimeIndex.hourThe hours of the datetime.
DatetimeIndex.minuteThe minutes of the datetime.
DatetimeIndex.secondThe seconds of the datetime.
DatetimeIndex.microsecondThe microseconds of the datetime.
DatetimeIndex.nanosecondThe nanoseconds of the datetime.
DatetimeIndex.dateReturns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information).
DatetimeIndex.timeReturns numpy array of datetime.time.
DatetimeIndex.timetzReturns numpy array of datetime.time also containing timezone information.
DatetimeIndex.dayofyearThe ordinal day of the year.
DatetimeIndex.weekofyearThe week ordinal of the year.
DatetimeIndex.weekThe week ordinal of the year.
DatetimeIndex.dayofweekThe day of the week with Monday=0, Sunday=6.
DatetimeIndex.weekdayThe day of the week with Monday=0, Sunday=6.
DatetimeIndex.quarterThe quarter of the date.
DatetimeIndex.tz
DatetimeIndex.freqReturn the frequency object if it is set, otherwise None.
DatetimeIndex.freqstrReturn the frequency object as a string if it is set, otherwise None.
DatetimeIndex.is_month_startIndicates whether the date is the first day of the month.
DatetimeIndex.is_month_endIndicates whether the date is the last day of the month.
DatetimeIndex.is_quarter_startIndicator for whether the date is the first day of a quarter.
DatetimeIndex.is_quarter_endIndicator for whether the date is the last day of a quarter.
DatetimeIndex.is_year_startIndicate whether the date is the first day of a year.
DatetimeIndex.is_year_endIndicate whether the date is the last day of the year.
DatetimeIndex.is_leap_yearBoolean indicator if the date belongs to a leap year.
DatetimeIndex.inferred_freqTryies to return a string representing a frequency guess, generated by infer_freq.

Selecting

DatetimeIndex.indexer_at_time(self, time[, asof])Return index locations of index values at particular time of day (e.g.
DatetimeIndex.indexer_between_time(self, …)Return index locations of values between particular times of day (e.g., 9:00-9:30AM).

Time-specific operations

DatetimeIndex.normalize(self, *args, **kwargs)Convert times to midnight.
DatetimeIndex.strftime(self, *args, **kwargs)Convert to Index using specified dateformat.
DatetimeIndex.snap(self[, freq])Snap time stamps to nearest occurring frequency
DatetimeIndex.tz_convert(self, *args, …)Convert tz-aware Datetime Array/Index from one time zone to another.
DatetimeIndex.tz_localize(self, *args, …)Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index.
DatetimeIndex.round(self, *args, **kwargs)Perform round operation on the data to the specified _freq.
DatetimeIndex.floor(self, *args, **kwargs)Perform floor operation on the data to the specified freq.
DatetimeIndex.ceil(self, *args, **kwargs)Perform ceil operation on the data to the specified freq.
DatetimeIndex.month_name(self, *args, …)Return the month names of the DateTimeIndex with specified locale.
DatetimeIndex.day_name(self, *args, **kwargs)Return the day names of the DateTimeIndex with specified locale.

Conversion

DatetimeIndex.to_period(self, *args, **kwargs)Cast to PeriodArray/Index at a particular frequency.
DatetimeIndex.to_perioddelta(self, *args, …)Calculate TimedeltaArray of difference between index values and index converted to PeriodArray at specified freq.
DatetimeIndex.to_pydatetime(self, *args, …)Return Datetime Array/Index as object ndarray of datetime.datetime objects
DatetimeIndex.to_series(self[, keep_tz, …])Create a Series with both index and values equal to the index keys useful with map for returning an indexer based on an index
DatetimeIndex.to_frame(self[, index, name])Create a DataFrame with a column containing the Index.

Methods

DatetimeIndex.mean(self, *args, **kwargs)Return the mean value of the Array.

TimedeltaIndex

TimedeltaIndexImmutable ndarray of timedelta64 data, represented internally as int64, and which can be boxed to timedelta objects

Components

TimedeltaIndex.daysNumber of days for each element.
TimedeltaIndex.secondsNumber of seconds (>= 0 and less than 1 day) for each element.
TimedeltaIndex.microsecondsNumber of microseconds (>= 0 and less than 1 second) for each element.
TimedeltaIndex.nanosecondsNumber of nanoseconds (>= 0 and less than 1 microsecond) for each element.
TimedeltaIndex.componentsReturn a dataframe of the components (days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) of the Timedeltas.
TimedeltaIndex.inferred_freqTryies to return a string representing a frequency guess, generated by infer_freq.

Conversion

TimedeltaIndex.to_pytimedelta(self, *args, …)Return Timedelta Array/Index as object ndarray of datetime.timedelta objects.
TimedeltaIndex.to_series(self[, 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.
TimedeltaIndex.round(self, freq[, …])Perform round operation on the data to the specified freq.
TimedeltaIndex.floor(self, freq[, …])Perform floor operation on the data to the specified freq.
TimedeltaIndex.ceil(self, freq[, ambiguous, …])Perform ceil operation on the data to the specified freq.
TimedeltaIndex.to_frame(self[, index, name])Create a DataFrame with a column containing the Index.

Methods

TimedeltaIndex.mean(self, *args, **kwargs)Return the mean value of the Array.

PeriodIndex

PeriodIndexImmutable ndarray holding ordinal values indicating regular periods in time such as particular years, quarters, months, etc.

Properties

PeriodIndex.dayThe days of the period
PeriodIndex.dayofweekThe day of the week with Monday=0, Sunday=6
PeriodIndex.dayofyearThe ordinal day of the year
PeriodIndex.days_in_monthThe number of days in the month
PeriodIndex.daysinmonthThe number of days in the month
PeriodIndex.end_time
PeriodIndex.freqReturn the frequency object if it is set, otherwise None.
PeriodIndex.freqstrReturn the frequency object as a string if it is set, otherwise None.
PeriodIndex.hourThe hour of the period
PeriodIndex.is_leap_yearLogical indicating if the date belongs to a leap year
PeriodIndex.minuteThe minute of the period
PeriodIndex.monthThe month as January=1, December=12
PeriodIndex.quarterThe quarter of the date
PeriodIndex.qyear
PeriodIndex.secondThe second of the period
PeriodIndex.start_time
PeriodIndex.weekThe week ordinal of the year
PeriodIndex.weekdayThe day of the week with Monday=0, Sunday=6
PeriodIndex.weekofyearThe week ordinal of the year
PeriodIndex.yearThe year of the period

Methods

PeriodIndex.asfreq(self, *args, **kwargs)Convert the Period Array/Index to the specified frequency freq.
PeriodIndex.strftime(self, *args, **kwargs)Convert to Index using specified date_format.
PeriodIndex.to_timestamp(self, *args, …)Cast to DatetimeArray/Index.