Polly
Polly

Reputation: 1097

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?

Upvotes: 6

Views: 18319

Answers (1)

EdChum
EdChum

Reputation: 393973

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

enter image description here

This will automatically plot the frequency of the unique values

Upvotes: 12

Related Questions