I would like to Display side by side two graphs containing the top 5 most popular French series and the top 5 most popular French films.
The number of votes numVotes for a series or a movie will be considered as a reliable indicator of its popularity.
top_france_tv = pd.Series(df[df['country'] == 'France']
ax = sns.countplot(y=top_france_tv, order=top_france_tv.value_counts().iloc[:5].index)
ax.tick_params(axis='y', length=0)
plt.tight_layout()
plt.show()
You can take the subset of top_france_tv
that are movies, then sort by averageRating
and take the first 5. Use this as the dataframe for a barplot
showing title
and averageRating
. Repeat for the tv shows.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns
sns.set()
np.random.seed(123)
df = pd.DataFrame({'type': np.random.choice(['Movie', 'TV Show'], 100),
'title': ["".join(np.random.choice([*'uvwxyz '], np.random.randint(5, 20))) for _ in range(100)],
'averageRating': np.random.uniform(1, 10, 100).round(1),
'country': np.random.choice(['France', 'other country'], 100)})
top_france_tv = df[df['country'] == 'France']
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12, 3), sharex=True)
for ax, mov_type in zip((ax1, ax2), ['Movie', 'TV Show']):
df_best_5 = top_france_tv[top_france_tv['type'] == mov_type].sort_values('averageRating', ascending=False)[:5]
sns.barplot(data=df_best_5, y='title', x='averageRating', palette='rocket', ax=ax)
ax.set_title('Best 5 French ' + mov_type + 's')
ax.set_ylabel('')
plt.tight_layout()
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.