'How to plot histogram groups of dataframe?
I have a dataframe of bins of page views in a specific site and the quantity of users in each bin a their share of users. It looks like that:
| index | 0-100 | 100-200 | 200-300 |
|---|---|---|---|
| usersquantity | 100 | 100 | 300 |
| usershare | 20 | 20 | 60 |
I am trying to plot a histogram of user quantity:
plt.hist(df.iloc[0], bins=[0,100,200,300])
But I get this error:
cannot determine next label for type <class 'str'>
I assume that this is because the index is categorical.
How can I fix this?
thanks a lot
Solution 1:[1]
Issue here is that, you are trying to use userquantity as a column.
If you want to print histogram for userquantity row, then you can do this. See further comments inline
#Delete the index column as it is text.
df_new = df.drop('index', axis=1)
#Use iloc to get the values from row 'userquantity'
plt.hist(df_new.iloc[0], bins=[0,100,200,300])
plt.show()
Output:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Manjunath K Mayya |

