Search code examples
pythondataframeseabornhistogram

Create histogram from DataFrame (where the index values are the variables)


I have a DataFrame containing the index and its respective values. For instance:

       | Count |
ID     
Amy    |   5   |
Chris  |   4   |
Gabe   |   2   |

How can I create a histplot from this DataFrame with the index as axis values?

I have done the following but it sets the count of each bar at 1.0:

sns.histplot(data=df, y=df.index)

Solution

  • A histogram is something you would use to show the distribution of a continuous variable. Since you just want to compare the count values between different categories, a barplot is more appropriate.

    sns.barplot(data=df, x='Count', y=df.index)
    

    barplot