Python Practice › Pandas Programs › Program 63
Index of a column
Write a pandas program to find the position of a column.
Output
2
Approach
df.columns.get_loc("col").
Solution
import pandas as pddf = pd.DataFrame({"sr_no": [1], "name": ["Alex"], "age": [30], "salary": [50000]})print(df.columns.get_loc("age"))Output
2
Learn the concept
New to this topic? Read the lesson, then come back.