What is the Pythonic way to generate a histogram using the data of each column of a Pandas dataframe?

+2 votes

Best answer

The **hist()** function of Pandas dataframe generates a histogram for each column. If the dataframe has a small number of columns, you can use this function.

Here is an example:

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

# create a dataframe with random numbers

np.random.seed(7)

df = pd.DataFrame(np.random.randn(100, 3), columns=['A', 'B', 'C'])

bp = df.hist(bins=10)

plt.show()

The above code will generate the following plot: