Skip to main content
`Ctrl`+`K`

# pandas.Index

class pandas.Index(data=None, dtype=None, copy=None, name=None, tupleize_cols=True)

  Immutable sequence used for indexing and alignment.

  The basic object storing axis labels for all pandas objects.

  Changed in version 2.0.0: Index can hold all numpy numeric dtypes (except float16). Previously only int64/uint64/float64 dtypes were accepted.

  Parameters:
    data array-like (1-dimensional)

      An array-like structure containing the data for the index. This could be a Python list, a NumPy array, or a pandas Series.

    dtype str, numpy.dtype, or ExtensionDtype, optional

      Data type for the output Index. If not specified, this will be inferred from data. See the user guide for more usages.

    copy bool, default None

      Whether to copy input data, only relevant for array, Series, and Index inputs (for other input, e.g. a list, a new array is created anyway). Defaults to True for array input and False for Index/Series. Set to False to avoid copying array input at your own risk (if you know the input data won’t be modified elsewhere). Set to True to force copying Series/Index input up front.

    name object

      Name to be stored in the index.

    tupleize_cols bool (default: True)

      When True, attempt to create a MultiIndex if possible.

  See also

  `RangeIndex`

    Index implementing a monotonic integer range.

  `CategoricalIndex`

    Index of `Categorical` s.

  `MultiIndex`

    A multi-level, or hierarchical Index.

  `IntervalIndex`

    An Index of `Interval` s.

  `DatetimeIndex`

    Index of datetime64 data.

  `TimedeltaIndex`

    Index of timedelta64 data.

  `PeriodIndex`

    Index of Period data.

  Notes

  An Index instance can only contain hashable objects. An Index instance can not hold numpy float16 dtype.

  Examples

      >>> pd.Index([1, 2, 3])
      Index([1, 2, 3], dtype='int64')

      >>> pd.Index(list("abc"))
      Index(['a', 'b', 'c'], dtype='str')

      >>> pd.Index([1, 2, 3], dtype="uint8")
      Index([1, 2, 3], dtype='uint8')

  Attributes

  `T` | Return the transpose, which is by definition self.
  `array` | The ExtensionArray of the data backing this Series or Index.
  `dtype` | Return the dtype object of the underlying data.
  `empty` | Indicator whether Index is empty.
  `has_duplicates` | Check if the Index has duplicate values.
  `hasnans` | Return True if there are any NaNs.
  `inferred_type` | Return a string of the type inferred from the values.
  `is_monotonic_decreasing` | Return a boolean if the values are equal or decreasing.
  `is_monotonic_increasing` | Return a boolean if the values are equal or increasing.
  `is_unique` | Return if the index has unique values.
  `name` | Return Index or MultiIndex name.
  `names` | Get names on index.
  `nbytes` | Return the number of bytes in the underlying data.
  `ndim` | Number of dimensions of the underlying data, by definition 1.
  `nlevels` | Number of levels.
  `shape` | Return a tuple of the shape of the underlying data.
  `size` | Return the number of elements in the underlying data.
  `values` | Return an array representing the data in the Index.

  Methods

  `all`(*args, **kwargs) | Return whether all elements are Truthy.
  `any`(*args, **kwargs) | Return whether any element is Truthy.
  `append`(other) | Append a collection of Index options together.
  `argmax`([axis, skipna]) | Return int position of the largest value in the Series.
  `argmin`([axis, skipna]) | Return int position of the smallest value in the Series.
  `argsort`(*args, **kwargs) | Return the integer indices that would sort the index.
  `asof`(label) | Return the label from the index, or, if not present, the previous one.
  `asof_locs`(where, mask) | Return the locations (indices) of labels in the index.
  `astype`(dtype[, copy]) | Create an Index with values cast to dtypes.
  `copy`([name, deep]) | Make a copy of this object.
  `delete`(loc) | Make new Index with passed location(-s) deleted.
  `diff`([periods]) | Computes the difference between consecutive values in the Index object.
  `difference`(other[, sort]) | Return a new Index with elements of index not in other.
  `drop`(labels[, errors]) | Make new Index with passed list of labels deleted.
  `drop_duplicates`(*[, keep]) | Return Index with duplicate values removed.
  `droplevel`([level]) | Return index with requested level(s) removed.
  `dropna`([how]) | Return Index without NA/NaN values.
  `duplicated`([keep]) | Indicate duplicate index values.
  `equals`(other) | Determine if two Index object are equal.
  `factorize`([sort, use_na_sentinel]) | Encode the object as an enumerated type or categorical variable.
  `fillna`(value) | Fill NA/NaN values with the specified value.
  `get_indexer`(target[, method, limit, tolerance]) | Compute indexer and mask for new index given the current index.
  `get_indexer_for`(target) | 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.
  `get_loc`(key) | Get integer location, slice or boolean mask for requested label.
  `get_slice_bound`(label, side) | Calculate slice bound that corresponds to given label.
  `groupby`(values) | Group the index labels by a given array of values.
  `identical`(other) | Similar to equals, but checks that object attributes and types are also equal.
  `infer_objects`([copy]) | If we have an object dtype, try to infer a non-object dtype.
  `insert`(loc, item) | Make new Index inserting new item at location.
  `intersection`(other[, sort]) | Form the intersection of two Index objects.
  `is_`(other) | More flexible, faster check like `is` but that works through views.
  `isin`(values[, level]) | Return a boolean array where the index values are in values.
  `isna`() | Detect missing values.
  `isnull`() | Detect missing values.
  `item`() | Return the first element of the underlying data as a Python scalar.
  `join`(other, *[, how, level, ...]) | Compute join_index and indexers to conform data structures to the new index.
  `map`(mapper[, na_action]) | Map values using an input mapping or function.
  `max`([axis, skipna]) | Return the maximum value of the Index.
  `memory_usage`([deep]) | Memory usage of the values.
  `min`([axis, skipna]) | Return the minimum value of the Index.
  `notna`() | Detect existing (non-missing) values.
  `notnull`() | Detect existing (non-missing) values.
  `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 a view on self.
  `reindex`(target[, method, level, limit, ...]) | Create index with target's values.
  `rename`(name, *[, inplace]) | Alter Index or MultiIndex name.
  `repeat`(repeats[, axis]) | Repeat elements of an Index.
  `round`([decimals]) | Round each value in the Index to the given number of decimals.
  `searchsorted`(value[, side, sorter]) | Find indices where elements should be inserted to maintain order.
  `set_names`(names, *[, level, inplace]) | Set Index or MultiIndex name.
  `shift`([periods, freq]) | Shift index by desired number of time frequency increments.
  `slice_indexer`([start, end, step]) | Compute the slice indexer for input labels and step.
  `slice_locs`([start, end, step]) | Compute slice locations for input labels.
  `sort_values`(*[, return_indexer, ascending, ...]) | Return a sorted copy of the index.
  `sortlevel`([level, ascending, ...]) | For internal compatibility with the Index API.
  `symmetric_difference`(other[, result_name, sort]) | 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_flat_index`() | Identity method.
  `to_frame`([index, name]) | Create a DataFrame with a column containing the Index.
  `to_list`() | Return a list of the values.
  `to_numpy`([dtype, copy, na_value]) | A NumPy ndarray representing the values in this Series or Index.
  `to_series`([index, name]) | Create a Series with both index and values equal to the index keys.
  `tolist`() | Return a list of the values.
  `transpose`(*args, **kwargs) | Return the transpose, which is by definition self.
  `union`(other[, sort]) | Form the union of two Index objects.
  `unique`([level]) | Return unique values in the index.
  `value_counts`([normalize, sort, ascending, ...]) | Return a Series containing counts of unique values.
  `view`([cls]) | Return a view of the Index with the specified dtype or a new Index instance.
  `where`(cond[, other]) | Replace values where the condition is False.