Python Practice › Pandas Programs › Program 64

All columns except one

EasyPandas Programs · 64 of 95

Write a pandas program to select all columns except one.

Advertisement
Output
   name  salary
0  Alex   50000
1  John   65000

Approach

  1. drop(columns=...).

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John"], "age": [30, 27], "salary": [50000, 65000]})print(df.drop(columns="age"))
Output
   name  salary
0  Alex   50000
1  John   65000
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs