Issue
Good afternoon everyone, i am a beginner in python i hope someone can help me ! I have in a dataframe a list of netflix movies and the number of votes that each of those movies receive. For example :
Title : The100 Votes : 1500
Title : Marania Votes : 2000
My question is simple :
Using seaborn and matplotlib i want to print in a figure the 5 movies which receive the the highest number of votes (with their number of votes).
What i try :
import seaborn as sns
...
sns.catplot(x='title', y='votes_number', data=top5_series)
But i don't really understand how i can only print the "5 best".
Thank you by advance !
Solution
You can do everything with pandas
import pandas as pd
import numpy as np
import string
np.random.seed(1)
df = pd.DataFrame(
{
"movie": [i for i in string.ascii_uppercase],
"vote": np.random.randint(low=10, high=500, size=len(string.ascii_uppercase))
}
)
# If you want a different number change the n_most
n_most = 5
df.nlargest(n_most , ["vote"]).plot(kind="bar", x="movie", y="vote", figsize=(15,6), rot=45)
Answered By - Eduardo Pacheco
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.