Movie Genre Analysis Project (Python)
Updated: Mar 5, 2025
This is my project analyzing real movie marketing data using Pandas for Data Analysis.
Here's the Link to the Full Code: https://github.com/mkitchens5/Merrill-Portfolio/blob/main/MovieGenre.ipynb
Movie Genre Analysis Project (Python)
Step 1: Importing Necessary Libraries and Loading Data
import pandas as pd
movies = pd.read_csv(r'C:\Users\Yeyian PC\Downloads\python excel\imdb_movies.csv')
moviesImports pandas to work with structured data.
Loads the dataset from a CSV file and assigns it to the variable movies.

Step 2: Checking Data Structure
Displays the number of rows and columns in the dataset.
Shows data types and missing values to understand the structure.

Step 3: Formatting Data
pd.set_option('display.max.rows', 11000)
pd.set_option('display.max.rows', 22)Adjusts settings to allow the display of more rows.
Step 4: Viewing Data
movies.head()Displays the first 5 rows of the dataset.

Step 5: Cleaning Data (Removing Duplicates)
movies.drop_duplicates(inplace=True)
movies[movies.duplicated()]Removes duplicate rows.
Checks if duplicates were successfully removed.

Step 6: Handling Missing Values in Genre Column
movies.dropna(subset=['genres'], inplace=True)
movies.info()Drops rows where 'genres' is missing since it is essential for analysis.
Verifies that missing values were removed.

Step 7: Adding a Profit Column
movies['profit'] = movies['revenue'] - movies['budget']
movies.head()Creates a new column to measure the profit per movie.
Displays the updated dataset to confirm changes.

Step 8: Selecting Relevant Columns
movies_data = movies[['popularity', 'budget', 'revenue', 'original_title', 'runtime', 'genres', 'release_year', 'vote_count', 'vote_average', 'profit']]
movies_data.head()Creates a new dataset with only necessary columns.

Step 9: Splitting Genre Column
movies_data['genres'].str.split('|')
split = movies_data['genres'].str.split('|').apply(pd.Series, 1).stack()
split.index = split.index.droplevel(-1)
split.name = 'genres_split'
del movies_data['genres']
movies_data = movies_data.join(split)
movies_dataSplits multiple genres into separate rows.
Creates a new column 'genres_split'.

Step 10: Analyzing Most Common Genres
genres_count = pd.DataFrame(movies_data.groupby('genres_split').original_title.nunique()).sort_values('original_title', ascending=False)
genres_count['original_title'].plot.pie(title='Movies Per Genre in %', autopct='%1.1f%%', figsize=(10,10))
genres_count2 = genres_count.sort_values('original_title', ascending=True)
genres_count2['original_title'].plot.barh(title='Movies Per Genre', color='DarkBlue', figsize=(10,9))Counts movies per genre.
Visualizes percentage distribution and bar chart.

Step 11: Budget and Revenue Analysis
genres_avg = movies_data.groupby('genres_split').mean(numeric_only=True)
pd.options.display.float_format = '{:2f}'.format
genres_avg[['budget', 'revenue']].plot.barh(title='Budget and Revenue by Genre', color=('DarkBlue', 'c'), figsize=(10,9))Calculates average budget and revenue per genre.
Formats numbers and plots a bar chart.

Step 12: Profit Analysis
genres_avg.sort_values('profit', ascending=True, inplace=True)
genres_avg['profit'].plot.barh(title='Profit by Genre', color='DarkBlue', figsize=(10,9))Sorts and visualizes profit per genre.

Step 13: Popularity Analysis
genres_avg.sort_values('popularity', ascending=True, inplace=True)
genres_avg['popularity'].plot.barh(title='Popularity by Genre', color='DarkBlue', figsize=(10,9))Sorts and visualizes average popularity per genre.

Step 14: High Rating Movie Analysis
vote_fifty = movies_data[(movies_data['vote_count'] >= 50) & (movies_data['vote_average'] >= 8)]
genres_vote50 = pd.DataFrame(vote_fifty.groupby('genres_split').vote_average.nunique()).sort_values('vote_average', ascending=True)
genres_vote50['vote_average'].plot.barh(title='Vote Average by Genre', color='DarkBlue', figsize=(10,9))Filters and analyzes highly rated movies.

Step 15: Research Hypothesis Testing
import numpy as np
movies_counted = movies_data[movies_data['vote_count'] >= 50]
movies_counted2 = movies_counted.select_dtypes(include=[np.number])
movies_counted3 = movies_counted2.corr(method='spearman')
print(movies_counted3)Computes correlation between variables.

Step 16: Popularity vs Revenue Correlation
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(12,6))
sns.regplot(x='popularity', y='revenue', data=movies_counted, line_kws={'color': 'red'})
plt.show()Visualizes the correlation between popularity and revenue.

Step 17: Additional Finding - Profit Per Genre Per Year
time_genre = pd.DataFrame(movies_data.groupby(['release_year', 'genres_split'])['profit'].mean())
final_genre = pd.pivot_table(time_genre, values='profit', index=['genres_split'], columns=['release_year'])
sns.heatmap(final_genre, cmap='YlGnBu', linewidths=0.5)
plt.title('Genres by Profit per Year')Analyzes profit trends per genre over time.

Findings:
Most Common Genres: Drama, Comedy, Thriller, and Action make up around 50% of all movies.
Highest Budget and Revenue: Action and Adventure have the highest budgets and revenues.
Highest Profitability: Animation and Adventure movies yield the highest profit.
Popularity Impact: Higher popularity correlates positively with higher revenue.
Highly Rated Movies: Mostly belong to Drama and Animation genres.
Budget vs Profit and Revenue: Higher budgets slightly increase profit and revenue.
Trends Over Time: Certain genres, like Sci-Fi and Fantasy, have shown increasing profits in recent years.
Conclusion:
This analysis provides insights into which genres perform best in terms of popularity, budget, revenue, and profitability. The correlations show trends between budget and financial success, helping guide future investments in movie production.
Link To FULL Code: https://github.com/mkitchens5/Merrill-Portfolio/blob/main/MovieGenre.ipynb
Author By: Merrill Kitchens




Nice job!!!!