Tsallaka zuwa abun ciki
Justice Tech School

Setting the Index

set_index makes a column the index and reset_index moves it back.

Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
d = df.set_index("name")
print(d.loc["Ada", "score"])
print(d.reset_index().columns.tolist())

Result

92
['name', 'country', 'score']

Exercise

Use name as index.

df.("name")

Quiz Test

What does reset_index do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.