lil-wolf
lil-wolf

Reputation: 382

dataframe.hist() with different bin size


Need to plot Histogram with bin size of each column unique value.
Specially used when each column has unique value of totally diff size.

Suppose, one col has 2 unique values, bin = 2
another col has 50 unique values, bin = 50
Here, I cannot define a common bin size

I already tried:

dataframe.hist(bins = dataframe.nunique())  

But this is not working.

Giving me this error:
ValueError: bins must increase monotonically, when an array

Upvotes: 1

Views: 1269

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150805

You can try this:

for col in df.columns:
    fig, ax = plt.subplots()
    df[col].value_counts().plot.bar(ax=ax)

Upvotes: 1

Related Questions