I have the following DataFrame (df):
DataFrame
df
import numpy as np import pandas as pd df = pd.DataFrame(np.random.rand(10, 5))
set():
set()
A simple approach is using set(), in particular when you have a long list of columns and do not want to handle them manually:
cols = list(set(df.columns.tolist()) - set(['mean'])) cols.insert(0, 'mean') df = df[cols]