+2 votes
in Programming Languages by (17.9k points)
What is the Pythonic way to generate a histogram using the data of each column of a Pandas dataframe?

1 Answer

+1 vote
by (28.5k points)

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:

histogram using pandas dataframe


...