import os
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/ProgramData/Anaconda3/Library/plugins/platforms'
As someone with three film credits and an interest in the entertainment industry, I wanted to explore some of the elements that are shared by the world’s highest-rated movies. The film industry is a constantly evolving part of society and the market is currently valued at $120.8 billion in 2026. This dataset contains information on the IMDb top 250 movies. For this project, I will analyze the data to find patterns among the most popular movies.
This data was gathered from the IMDb API which gives the user access to a wide range of information on the top movies. The dataset contains 250 records and 28 columns. Some of the variables included are the movie titles, release dates, ratings, countries of origin, production companies, filming locations, etc. By exploring the data, we are able to find relationships and patterns through data visualization.
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
import seaborn as sns
df = pd.read_csv("U:/DS736/" + "imdb_top_250_movies.csv")
This analysis uses the variables genre, decade, IMDb rating, runtime, and worldwide gross revenue to create visualizations. They explore which genres and decades have the highest-rated movies around the world. The correlation between multiple movie characteristics is also shown. All of these data visualizations will help us get a better understanding of the similarities and differences of the IMDb top 250 films.
This scatterplot shows the relationship between the runtime of each movie and its IMDb rating. Each data point represents a movie and its color tells us what the genre is. Several of the movies had multiple genres so the first genre listed was selected for analysis. The scatterplot does not show a strong relationship between runtime and rating. The runtime varies across the genres so the visualization does not show that one particular genre contains movies with a much longer or shorter runtime than the others. One movie that stands out is “The Best of Youth”, with a runtime of 374 minutes. This is significantly longer than the majority of the data which falls between 90 and 180 minutes.
# Create a new column with the first genre of each movie
df['mainGenre'] = df['genres'].str.split(', ').str[0]
plt.figure(figsize = (18, 10))
# Create a scatterplot for the genre with runtime against IMDb rating
for genre in df['mainGenre'].unique():
genre_data = df[df['mainGenre'] == genre]
plt.scatter(genre_data['runtimeMinutes'], genre_data['averageRating'], label = genre)
# Add a title, axis labels, and legend
plt.title('Movie Runtime vs IMDb Rating', fontsize = 20)
plt.xlabel('Runtime (Minutes)', fontsize = 14)
plt.ylabel('IMDb Rating', fontsize = 14)
plt.xticks(fontsize = 14)
plt.yticks(fontsize = 14)
plt.grid(True, alpha=0.3)
plt.legend(title = 'Genre', fontsize = 14)
plt.show()
This bar chart shows the IMDb top 250 movies released by decade. To group the movies by decade, a new column was created using the variable startYear. The barchart shows an increase in the number of movies throughout the years with the 2000s having the highest number of 48 movies. Movies in the 2020s were removed from the chart because the decade is incomplete and does not allow for a full comparison with previous decades.
# Create a new column that groups movies by decade
df['startYear'] = df['startYear'].astype(int)
df['decade'] = (df['startYear'] // 10) * 10
# Remove movies from the 2020s
df_decade = df[df['decade'] < 2020]
# Count movies by decade
decade_count = df_decade['decade'].value_counts().sort_index()
plt.figure(figsize = (18, 10))
ax1 = decade_count.plot(kind = 'bar', color = 'lightblue')
# Add movie counts to the bars
ax1.bar_label(ax1.containers[0], label_type = 'edge', fontsize = 14)
# Add a title and axis labels
plt.title('IMDb Top 250 Movies by Decade', fontsize = 20)
plt.xlabel('Decade', fontsize = 14)
plt.ylabel('Number of Movies', fontsize = 14)
plt.xticks(fontsize = 14, rotation = 0)
plt.yticks(fontsize = 14)
plt.show()
This donut chart shows the IMDb top 250 movies by genre. The same approach from the scatterplot was used to include only the first genre of each movie in the analysis. The genre categories were stored as strings so I had to remove any extra characters when splitting them. Any genre with less than 10 movies were grouped into a new category called “Other” to make the visualization easier to read. Drama is the genre with the highest percentage of movies at 27.60%.
# Data cleaning
df['mainGenre'] = df['genres'].str.replace('[', '', regex = False)
df['mainGenre'] = df['mainGenre'].str.replace(']', '', regex = False)
df['mainGenre'] = df['mainGenre'].str.replace("'", '', regex = False)
df['mainGenre'] = df['mainGenre'].str.split(', ').str[0]
# Keep genres with at least 10 movies
all_genres = df['mainGenre'].value_counts()
genre_count = all_genres[all_genres >= 10].copy()
genre_count['Other'] = all_genres[all_genres < 10].sum()
fig = plt.figure(figsize = (10, 10))
ax = fig.add_subplot(1, 1, 1)
# Find the largest genre to explode
largest_genre = genre_count.argmax()
explode = [0] * len(genre_count)
explode[largest_genre] = 0.1
# Set colors for each genre
colormap = plt.get_cmap("tab20c")
colors = colormap(range(len(genre_count)))
all_movies = genre_count.sum()
# Create donut chart of movies by their main genre
genre_count.plot(kind = 'pie', radius = 1, colors = colors, explode = explode,
pctdistance = 0.8, labeldistance = 1.1,
wedgeprops = dict(edgecolor = 'white'), textprops = {'fontsize':14},
autopct = '%1.2f%%', shadow = True, startangle = 90)
# Add circle to the center
hole = plt.Circle((0, 0), 0.3, fc = 'white')
fig.gca().add_artist(hole)
ax.yaxis.set_visible(False)
plt.title('IMDb Top 250 Movies by Main Genre', fontsize = 16)
ax.text(0, 0, 'Total Movies\n' + str(all_movies), size = 14, ha = 'center', va = 'center')
ax.axis('equal')
plt.tight_layout()
plt.show()
This line plot compares the average worldwide gross revenue across different decades and genres. Each line represents one of the six genres. The earlier decades had very little movies represented by the genres so they were removed from the analysis. As with our bar chart, movies in the 2020s were removed because the decade is incomplete and does not allow for a full comparison with previous decades. As a result, the x-axis only includes movies from 1970 to 2010. Adventure movies show the most consistent growth across the genres as their revenue increases throughout each decade. They have the highest average revenue from 1980-2010.
# Create decade column using the movie's start year
df['decade'] = (df['startYear'] // 10) * 10
df['mainGenre'] = df['genres'].str.split(', ').str[0]
df['mainGenre'] = df['genres'].str.replace('[', '', regex = False)
df['mainGenre'] = df['mainGenre'].str.replace(']', '', regex = False)
df['mainGenre'] = df['mainGenre'].str.replace("'", '', regex = False)
df['mainGenre'] = df['mainGenre'].str.split(', ').str[0]
# Keep the six most common genres
df_line = df[df['mainGenre'].isin(['Drama', 'Action', 'Adventure', 'Crime', 'Biography', 'Comedy'])]
df_line = df_line[(df_line['decade'] >= 1970) & (df_line['decade'] < 2020)]
# Calculate average worldwide revenue by decade and genre
revenue = df_line.pivot_table(values = 'grossWorldwide', index = 'decade', columns = 'mainGenre', aggfunc = 'mean')
fig = plt.figure(figsize = (18, 10))
ax = fig.add_subplot(1, 1, 1)
# Create a line for each genre
for key in revenue.columns:
ax.plot(revenue.index, revenue[key], label = key, marker = 'o')
# Add a title, axis labels, and legend
plt.title('Average Worldwide Revenue by Decade and Genre', fontsize = 18)
ax.set_xlabel('Decade', fontsize = 18)
ax.set_ylabel('Average Worldwide Revenue (Billion $)', fontsize = 18)
ax.tick_params(axis = 'x', labelsize = 14)
ax.tick_params(axis = 'y', labelsize = 14)
plt.legend(title = 'Genre', loc = 'best', fontsize = 12)
ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '$%1.1fB' % (x * 1e-9)))
plt.show()
This heatmap shows the correlations between the variables: averageRating, metascore, numVotes, runtimeMinutes, and grossWorldwide. The map uses colors to measure the strength and direction of the relationship between these five variables. The strongest positive correlation of 0.55 is between IMDb ratings and number of votes. Movies with more votes tend to have higher ratings and higher gross worldwide revenue, although these correlations are moderate.
# Calculate correlation for five movie variables
hm_df = df[['averageRating', 'metascore', 'numVotes', 'runtimeMinutes', 'grossWorldwide']].corr()
fig = plt.figure(figsize = (12, 10))
ax = fig.add_subplot(1, 1, 1)
# Change x and y axis variable names
hm_df = hm_df.rename(columns = {'averageRating':'IMDb Rating', 'metascore':'Metascore', 'numVotes':'Number of Votes', 'runtimeMinutes':'Runtime', 'grossWorldwide':'Worldwide Revenue'})
hm_df = hm_df.rename(index = {'averageRating':'IMDb Rating', 'metascore':'Metascore', 'numVotes':'Number of Votes', 'runtimeMinutes':'Runtime', 'grossWorldwide':'Worldwide Revenue'})
# Create heatmap
ax = sns.heatmap(hm_df, linewidth = 0.2, annot = True, cmap = 'coolwarm', fmt = '.2f', square = True, annot_kws = {'size':12}, vmin = -1, vmax = 1, center = 0)
# Add a title and axis labels
plt.title('Correlation Between IMDb Movie Characteristics', fontsize = 18, pad = 15)
plt.xlabel('Movie Characteristics', fontsize = 16, labelpad = 10)
plt.ylabel('Movie Characteristics', fontsize = 16, labelpad = 10)
plt.xticks(size = 12, rotation = 0, ha = 'center')
plt.yticks(size = 12, rotation = 0)
cbar = ax.collections[0].colorbar
cbar.set_label('Correlation', rotation = 270, fontsize = 14, labelpad = 20)
plt.tight_layout()
plt.show()
This project allowed me to analyze some of the variables of the top 250 films from across the world. By creating visualizations using Python, I was able to find patterns in the data that can help us understand what factors are associated with the most highly rated movies. We found that the movies had a large range of runtimes and varied across the genres. We also found an increase in the number of movies being included in the top 250 as the years go on. The revenue analysis also showed the differences between genres over the decades. Adventure, Action, and Crime showed the most increase in average revenue in the 2000s. This analysis helps us understand that there is not a singular factor that explains why a film is successful.