Nycolas Mancini
Nycolas Mancini

Reputation: 153

Can't sort values before plotting

Here is what I'm trying to do: I currently have the below plot

x=frequencia['Numero']
y=frequencia['Recorrencia']
plt.bar(x,y)

I'm trying to plot the first 10 highest values. For that, I can sort my DataFrame with

frequencia.sort_values(by=['Recorrencia'], inplace=True, ascending=False)

But if I try to print the first 10 values using .head(10), all I get is this second plot.

enter image description here

Is there a way to plot it like below instead?

enter image description here

Upvotes: 1

Views: 62

Answers (1)

Derek O
Derek O

Reputation: 19610

Try: frequencia = frequencia.sort_values(by=['Recorrencia'])

Then extract the x, y variables to be plotted:

x=frequencia['Numero']
y=frequencia['Recorrencia']
plt.bar(x,y)

Upvotes: 1

Related Questions