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

1 Answer

+2 votes
by (73.8k points)
selected by
 
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:

histogram using pandas dataframe


...