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
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.