reset_index()
noun
say it: “REE-set IN-deks” /ˌriˈsɛt ˈɪndɛks/
A pandas method that gives a table plain row numbers again from 0, either keeping the old row labels as a column or throwing them away.
What does reset_index() do in pandas?
reset_index() is a pandas method that numbers a table's rows 0, 1, 2 again. The old row labels, such as the
groups a groupby() made, become an ordinary column; with drop=True they're thrown away instead.
import pandas as pd
orders = pd.DataFrame({"size": ["small", "large", "small"], "total": [12.0, 20.0, 14.0]})
by_size = orders.groupby("size")["total"].sum().reset_index()
print(by_size)
# size total
# 0 large 20.0
# 1 small 26.0
In a sentence
- “Her top-ten list was numbered 0 to 9 after reset_index() with drop=True.”
- “After the groupby, reset_index() turned the sizes back into an ordinary column.”
Level: Journeyman · More Python terms at this level
Updated