ashish_goy
ashish_goy

Reputation: 31

Bar plot in python for categorical data

I am trying to create a bar for one of the column in dataset. Column name is glucose and need a bar plot for three categoric values 0-100, 1-150, 151-200.

X=dataset('Glucose')

X.head(20)

0     148
1      85
2     183
3      89
4     137
5     116
6      78
7     115
8     197
9     125
10    110
11    168
12    139
13    189
14    166
15    100
16    118
17    107
18    103
19    115

not sure which approach to follow. could anyone please guide.

Upvotes: 0

Views: 182

Answers (2)

ashish_goy
ashish_goy

Reputation: 31

bins=pd.IntervalIndex.from_tuples([(0,100),(101,150),(151,200)])

Upvotes: 0

anky
anky

Reputation: 75080

You can use pd.cut (Assuming X is a series) with value_counts:

pd.cut(X,[0,100,150,200]).value_counts().plot.bar()

enter image description here

Upvotes: 1

Related Questions