Python Practice › Pandas Programs › Program 63

Index of a column

EasyPandas Programs · 63 of 95

Write a pandas program to find the position of a column.

Advertisement
Output
2

Approach

  1. df.columns.get_loc("col").

Solution

Python
import pandas as pddf = pd.DataFrame({"sr_no": [1], "name": ["Alex"], "age": [30], "salary": [50000]})print(df.columns.get_loc("age"))
Output
2
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs