0

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 call `fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,6))`. And then `sns.countplot(...., ax=ax1)` for one plot and `sns.countplot(...., ax=ax2)` for the other. – JohanC Apr 13 '21 at 19:05
  • Thanks but I don't know how I can get the top 5 best rated French films –  Apr 15 '21 at 21:09

1 Answers1

1

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()

find 5 best

JohanC
  • 71,591
  • 8
  • 33
  • 66