Home > Back-end >  Pandas - Want to plot the top 20 Prices (float) for Sire (string)
Pandas - Want to plot the top 20 Prices (float) for Sire (string)

Time:08-10

Hi I'm new to Pandas so any help is much appreciated. I would like to show the top 20 performing Sires (string) by Price (float).

I am currently using

df.nlargest(n=20, columns=['Price'])

which gives me a list of the top 20 prices. I now want to plot this.

I currently have

df.groupby('Sire').sum().plot(y='Price', kind='bar')

but this gives me a list of all Sires rather than the top 20 by price.

any help is very much appreciated.

CodePudding user response:

Without knowing what the structure of your DataFrame looks like it is hard to help. You might just try doing both operations. Perhaps something like:

df.groupby('Sire').sum().nlargest(n=20, columns=['Price']).plot(y='Price', kind='bar')

or

df.nlargest(n=20, columns=['Price']).groupby('Sire').sum().plot(y='Price', kind='bar')
  • Related