how to select a range of columns in pandas code example
Example 1: how to keep only certain columns in dataframe
df.drop(df.columns[[1, 2]], axis=1, inplace=True)
df1 = df1.drop(['B', 'C'], axis=1)
df1 = df[['a','d']]
Example 2: select columns pandas
df1 = df.iloc[:,0:2]
Example 3: python pandas selecting multiple columns
import pandas as pd
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
'Age':[27, 24, 22, 32],
'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'],
'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
df = pd.DataFrame(data)
df[['Name', 'Qualification']]