Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: plot the graph of unique values

I have a column in pandas dataframe:

df.['A']:
1
1
1
2
2
3
1
2
3
1
2
3

I need to plot a histogram which will show how much if 1, of 2 and of 3 i have. For that i firstly count the amount of all 1, 2, and 3:

print df.groupby(df.index)['A'].nunique()

but instead of getting

1   5
2   4
3   3

i get

1
1
1

what is my mistake? and may be there is a better way of plotting it withpout previous extraction of counted data?

like image 549
Polly Avatar asked Apr 11 '16 10:04

Polly


1 Answers

IIUC you can just call df['A'].hist():

enter image description here

This will automatically plot the frequency of the unique values

like image 134
EdChum Avatar answered Nov 03 '22 02:11

EdChum