Examples
import numpy as np
import pandas as pd
df = pd.DataFrame(np.arange(12).reshape(3, 4),
columns=['P', 'Q', 'R', 'S'])
df
Drop columns:
df.drop(['Q', 'R'], axis=1)
df.drop(columns=['Q', 'R'])
Drop a row by index:
df.drop([0, 1])
Drop columns and/or rows of MultiIndex DataFrame
midx = pd.MultiIndex(levels=[['deer', 'dog', 'eagle'],
['speed', 'weight', 'length']],
codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
[0, 1, 2, 0, 1, 2, 0, 1, 2]])
df = pd.DataFrame(index=midx, columns=['big', 'small'],
data=[[60, 35], [30, 12], [5.5, 1], [40, 20],
[25, 10], [4.5, 0.8], [320, 220],
[2, 0.8], [2.2, 0.2]])
df
df.drop(index='dog', columns='small')
df.drop(index='length', level=1)