Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Class

Index

pandas.Index is an immutable sequence of labels used for indexing and alignment. It is the core axis-label object used by pandas Series and DataFrame objects.

How it works

pandas.Index creates an immutable, one-dimensional sequence of axis labels. Construct it from array-like data, optionally controlling its dtype, name, copying behavior, and whether tuple-like data should become a MultiIndex.

Syntax

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

Parameters

NameTypeDescription
dataarray-like, optionalOne-dimensional array-like data for the labels, such as a list, NumPy array, or pandas Series.
dtypestr, numpy.dtype, or ExtensionDtype, optionalRequested output data type; if omitted, pandas infers it from data.
copybool, default FalseWhether to copy the input data.
nameobject, optionalName stored on the Index.
tupleize_colsbool, default TrueWhether to attempt MultiIndex construction from suitable tuple-like data.

Returns

A pandas.Index object containing the supplied labels.

Key points

  • An Index provides stable labels for selecting and aligning pandas data.
  • DataFrame and Series axes use Index objects to represent their labels.
  • The constructor accepts one-dimensional array-like input, including lists, NumPy arrays, and Series.
  • When dtype is omitted, pandas determines a suitable dtype from the input labels.
  • tupleize_cols can turn suitable tuple-like input into hierarchical index structure.
  • Numeric Index dtypes are broadly supported, with numpy.float16 as the documented exception.

Common mistakes

  • Index labels must be hashable; mutable values such as lists cannot be used as labels.
  • numpy.float16 is not supported as an Index dtype.

Example: Create and use an Index

import pandas as pd

labels = pd.Index(["a", "b", "c"], name="label")
frame = pd.DataFrame({"value": [10, 20, 30]}, index=labels)
print(frame.loc["b", "value"])
print(frame.index.name)

Creates a named Index and uses it as a DataFrame axis for label-based selection.

When to use it

Label rows

Use an Index to assign meaningful row labels to a DataFrame and select records with .loc.

Name an axis

Use named Index objects to make axis meaning explicit in downstream transformations.

Prepare labels

Construct an Index from existing one-dimensional data before alignment or comparison operations.

Interview questions

QWhat is pandas.Index, and what input does it accept?

pandas.Index is an immutable sequence used for indexing and alignment, and it stores axis labels for pandas objects. It can be constructed from one-dimensional array-like input such as a list, NumPy array, or Series.

Follow-up: How does tupleize_cols affect construction? When true, pandas attempts to create a MultiIndex when the input makes that possible.

QWhat are the main constructor parameters?

The data argument supplies one-dimensional array-like labels. dtype can request the output dtype, name stores an index name, copy controls whether the input is copied, and tupleize_cols controls possible MultiIndex creation.

Follow-up: What happens if dtype is omitted? pandas infers the dtype from the supplied data.

QWhat constraints apply to Index values?

Index objects are immutable and require hashable elements, which makes them suitable for stable axis labels and alignment. They support numeric dtypes broadly, except that numpy.float16 cannot be held.

Follow-up: Can an Index contain mutable Python objects? No; mutable objects are not hashable and therefore cannot be Index elements.

  • DataFrame
  • Series
  • MultiIndex
  • RangeIndex
  • CategoricalIndex
  • IntervalIndex
  • DatetimeIndex
  • TimedeltaIndex

Source: pandas.Index. Checked 2026-10-15.