How do I create histograms for all variables except one in Python?

Question:

df.hist() gives you histograms for all variables.
df.hist(column='age') gives you a histogram for just age.

What if I want histograms for all variables except one? Do I have to do them separately? And what’s the difference between using df.hist() and the Matplotlib version anyway?

Asked By: Emily

||

Answers:

df.hist(column=["Category 1", "Category 2", "Category 3", "Category 4", "Category 5"])

Try using this.

Answered By: DholuBholu

Save the column that you want to exclude in a variable:
exclude = ["age"]

And the plot the histogram accordingly:
df.loc[:, df.columns.difference(exclude)].hist(figsize=(15, 10));

This should solve your problem.

Answered By: Paschalis Ag