application_vnd.jupyter.stderr_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

imdb_all = pd.read_csv('/kaggle/input/imdb-dataset-of-top-1000-movies-and-tv-shows/imdb_top_1000.csv')

imdb_all['Gross'] = imdb_all['Gross'].str.replace(',', '')
imdb_all['Gross'] = pd.to_numeric(imdb_all['Gross'])
imdb_all['Gross'] = imdb_all['Gross'].fillna(imdb_all['Gross'].mean())
imdb_all['Certificate'] = imdb_all['Certificate'].fillna('No certificate')
imdb_all['Meta_score'] = imdb_all['Meta_score'].fillna(imdb_all['Meta_score'].mean())

import seaborn as sns
import matplotlib.pyplot as plt

director_gross = imdb_all[['Director', 'Gross']]
director_gross = director_gross.groupby('Director').agg(['mean', 'count'])
df = director_gross.sort_values(('Gross', 'mean'), ascending=False)[:20]
df['Gross', 'mean'] = round(df['Gross', 'mean'] / 1000000, 2)

color_map = ['#F2DB83' for _ in range(20)]
color_map[0] = color_map[1] = color_map[2] = '#000000'
fig, ax = plt.subplots(1, 1, figsize=(12, 6))
ax.bar(df.index, df['Gross', 'mean'], width=0.5, edgecolor='darkgray', linewidth=0.6, color=color_map)
ax.set_xticklabels(df.index, fontfamily='serif', rotation=55)
fig.text(0.09, 0.95, 'Top 20 directors by mean gross', fontsize=13, fontweight='bold', fontfamily='serif')
fig.text(0.09, 0.9, '\nAs you can see the most profitable director is Anthony Russo and just behind him are Gareth Edwards and JJ. Abrams\n', fontsize=10, fontweight='light', fontfamily='serif')
grid_y_ticks = np.arange(0, 700, 100)
ax.set_yticks(grid_y_ticks)
plt.show()