pandas.DataFrame.set_index
pandas 3.1.1 · DataFrame · method
Use columns or supplied arrays as the row index.
Call syntax
DataFrame.set_index(keys, *, drop=True, append=False, inplace=…, verify_integrity=…)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
keys |
Required Positional or keyword |
label or array-like or list of labels/arrays Provide grouping, dictionary, index, or concatenation keys for this operation. |
drop |
Optional Keyword only Default True |
bool Choose whether removed labels or levels are kept as data where supported. |
append |
Optional Keyword only Default False |
bool Add records or keys to existing output instead of replacing it where supported. |
inplace |
Optional Keyword only |
bool Choose whether to change the existing object. Where supported, an in-place call typically returns None. |
verify_integrity |
Optional Keyword only |
bool Check that the result satisfies the API's integrity requirements, such as unique labels. |
Returns
DataFrame or None