{"id":196,"date":"2026-09-03T10:51:07","date_gmt":"2026-09-03T10:51:07","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=196"},"modified":"2026-09-03T10:51:07","modified_gmt":"2026-09-03T10:51:07","slug":"perform-eda-on-movie-csv","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2026\/09\/03\/perform-eda-on-movie-csv\/","title":{"rendered":"Perform EDA on Movie csv"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Create a CSV file named movies.csv with the following attributes: (Movie ID, Title, Genre, Rating, BoxOfficeCollection, Year). Store at least 20 records. Perform EDA<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># ============================================<br># Q1. Movie Data Analysis - EDA<br># ============================================<br><br>import pandas as pd<br>import numpy as np<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br><br># ============================================<br># Part 1: Create CSV file with Indian Movies<br># ============================================<br><br># Creating dataset of Indian movies (Bollywood, Tollywood, etc.)<br>movies_data = {<br>    'Movie ID': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, <br>                 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],<br>    'Title': ['Jawan', 'Pathaan', 'Gadar 2', 'Animal', 'KGF 2', <br>              'RRR', 'Pushpa', 'Bahubali 2', 'Dangal', 'PK',<br>              '3 Idiots', 'Gully Boy', 'Andhadhun', 'Uri', 'War',<br>              'Tiger Zinda Hai', 'Padmaavat', 'Sanju', 'Sultan', 'Dhoom 3'],<br>    'Genre': ['Action', 'Action', 'Action', 'Crime', 'Action',<br>              'Action', 'Action', 'Action', 'Drama', 'Comedy',<br>              'Comedy', 'Drama', 'Thriller', 'Action', 'Action',<br>              'Action', 'Drama', 'Biopic', 'Sports', 'Action'],<br>    'Rating': [8.1, 7.5, 7.9, 8.6, 8.5, <br>               8.9, 7.8, 9.0, 8.7, 8.2,<br>               8.4, 8.0, 8.3, 8.5, 8.6,<br>               7.3, 7.8, 7.9, 8.2, 7.5],<br>    'BoxOfficeCollection': [640, 550, 520, 490, 460,<br>                            430, 390, 360, 330, 300,<br>                            280, 260, 240, 220, 200,<br>                            190, 180, 170, 160, 150],<br>    'Year': [2023, 2023, 2023, 2023, 2022,<br>             2022, 2021, 2017, 2016, 2014,<br>             2009, 2019, 2018, 2019, 2019,<br>             2017, 2018, 2018, 2016, 2013]<br>}<br><br># Convert to DataFrame<br>df_movies = pd.DataFrame(movies_data)<br><br># Save to CSV<br>df_movies.to_csv('movies.csv', index=False)<br>print(\"movies.csv created successfully!\\n\")<br><br># ============================================<br># Part 2: Load dataset<br># ============================================<br><br>df = pd.read_csv('movies.csv')<br>print(\"=\"*60)<br>print(\"PART 2: Dataset Loaded Successfully\")<br>print(\"=\"*60)<br><br># ============================================<br># Part 3: Display top 5 movies<br># ============================================<br><br>print(\"\\n\" + \"=\"*60)<br>print(\"PART 3: Top 5 Movies\")<br>print(\"=\"*60)<br>print(df.head())<br><br># ============================================<br># Part 4: Univariate Analysis on Rating<br># ============================================<br><br>print(\"\\n\" + \"=\"*60)<br>print(\"PART 4: Univariate Analysis on Rating\")<br>print(\"=\"*60)<br><br># Descriptive statistics<br>print(\"\\n Descriptive Statistics for Rating:\")<br>print(df['Rating'].describe())<br><br># Additional statistics<br>print(f\"\\n Mode of Rating: {df['Rating'].mode().values[0]}\")<br>print(f\" Variance of Rating: {df['Rating'].var():.3f}\")<br>print(f\" Standard Deviation: {df['Rating'].std():.3f}\")<br>print(f\" Skewness: {df['Rating'].skew():.3f}\")<br>print(f\" Kurtosis: {df['Rating'].kurtosis():.3f}\")<br><br># Count of movies by rating range<br>rating_bins = [7.0, 7.5, 8.0, 8.5, 9.0, 9.5]<br>rating_labels = ['7.0-7.5', '7.5-8.0', '8.0-8.5', '8.5-9.0', '9.0-9.5']<br>df['Rating_Range'] = pd.cut(df['Rating'], bins=rating_bins, labels=rating_labels, right=False)<br>print(\"\\n Distribution by Rating Range:\")<br>print(df['Rating_Range'].value_counts().sort_index())<br><br># Visualization - Histogram<br>plt.figure(figsize=(12, 5))<br><br>plt.subplot(1, 2, 1)<br>plt.hist(df['Rating'], bins=8, color='skyblue', edgecolor='black', alpha=0.7)<br>plt.xlabel('Rating')<br>plt.ylabel('Frequency')<br>plt.title('Distribution of Movie Ratings')<br>plt.axvline(df['Rating'].mean(), color='red', linestyle='dashed', linewidth=2, label=f'Mean: {df[\"Rating\"].mean():.2f}')<br>plt.axvline(df['Rating'].median(), color='green', linestyle='dashed', linewidth=2, label=f'Median: {df[\"Rating\"].median():.2f}')<br>plt.legend()<br><br># Box plot<br>plt.subplot(1, 2, 2)<br>plt.boxplot(df['Rating'], vert=True)<br>plt.ylabel('Rating')<br>plt.title('Box Plot of Movie Ratings')<br>plt.grid(True, alpha=0.3)<br><br>plt.tight_layout()<br>plt.show()<br><br># ============================================<br># Part 5: Bivariate Analysis between Year and BoxOfficeCollection<br># ============================================<br><br>print(\"\\n\" + \"=\"*60)<br>print(\"PART 5: Bivariate Analysis - Year vs BoxOfficeCollection\")<br>print(\"=\"*60)<br><br># Group by Year to see trend<br>yearly_collection = df.groupby('Year')['BoxOfficeCollection'].agg(['sum', 'mean', 'count']).sort_index()<br>print(\"\\n\ud83d\udcca Year-wise Box Office Collection:\")<br>print(yearly_collection)<br><br># Scatter plot with regression line<br>plt.figure(figsize=(12, 5))<br><br>plt.subplot(1, 2, 1)<br>plt.scatter(df['Year'], df['BoxOfficeCollection'], alpha=0.6, s=100, color='coral')<br>plt.xlabel('Year')<br>plt.ylabel('Box Office Collection (in Crores \u20b9)')<br>plt.title('Year vs Box Office Collection')<br>plt.grid(True, alpha=0.3)<br><br># Add trend line<br>z = np.polyfit(df['Year'], df['BoxOfficeCollection'], 1)<br>p = np.poly1d(z)<br>plt.plot(df['Year'].sort_values(), p(df['Year'].sort_values()), \"r--\", linewidth=2, label='Trend Line')<br>plt.legend()<br><br># Bar plot - Average collection by year<br>plt.subplot(1, 2, 2)<br>yearly_avg = df.groupby('Year')['BoxOfficeCollection'].mean().sort_index()<br>plt.bar(yearly_avg.index.astype(str), yearly_avg.values, color='lightgreen', edgecolor='black')<br>plt.xlabel('Year')<br>plt.ylabel('Average Collection (in Crores \u20b9)')<br>plt.title('Average Box Office Collection by Year')<br>plt.xticks(rotation=45)<br>plt.grid(True, alpha=0.3, axis='y')<br><br>plt.tight_layout()<br>plt.show()<br><br># Correlation between Year and BoxOfficeCollection<br>correlation_year = df['Year'].corr(df['BoxOfficeCollection'])<br>print(f\"\\n Correlation between Year and BoxOfficeCollection: {correlation_year:.3f}\")<br><br># ============================================<br># Part 6: Multivariate correlation matrix<br># ============================================<br><br>print(\"\\n\" + \"=\"*60)<br>print(\"PART 6: Multivariate Correlation Matrix\")<br>print(\"=\"*60)<br><br># Select numerical columns for correlation<br>numerical_cols = ['Movie ID', 'Rating', 'BoxOfficeCollection', 'Year']<br>correlation_matrix = df[numerical_cols].corr()<br><br>print(\"\\n Correlation Matrix:\")<br>print(correlation_matrix)<br><br># Heatmap visualization<br>plt.figure(figsize=(8, 6))<br>sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt='.3f', <br>            linewidths=0.5, square=True, cbar_kws={\"shrink\": 0.8})<br>plt.title('Correlation Matrix of Movie Features')<br>plt.show()<br><br># ============================================<br># Part 7: Detect and handle missing values<br># ============================================<br><br>print(\"\\n\" + \"=\"*60)<br>print(\"PART 7: Detect and Handle Missing Values\")<br>print(\"=\"*60)<br><br># Check for missing values<br>print(\"\\n Missing Values Count:\")<br>print(df.isnull().sum())<br><br># Check percentage of missing values<br>print(\"\\n Percentage of Missing Values:\")<br>print((df.isnull().sum() \/ len(df)) * 100)<br><br># Create a copy with some missing values for demonstration<br>df_with_missing = df.copy()<br><br># Insert some missing values (for demonstration)<br># In real scenario, these would already be present<br>df_with_missing.loc[0, 'Rating'] = np.nan  # Add missing rating for movie 1<br>df_with_missing.loc[2, 'BoxOfficeCollection'] = np.nan  # Add missing box office for movie 3<br><br>print(\"\\n After Inserting Missing Values (Demo):\")<br>print(df_with_missing.head())<br><br># Handling missing values - Method 1: Drop rows with missing values<br>df_dropped = df_with_missing.dropna()<br>print(f\"\\n After dropping rows with missing values: {len(df_dropped)} rows remaining\")<br><br># Handling missing values - Method 2: Fill with mean (for numerical columns)<br>df_filled = df_with_missing.copy()<br>df_filled['Rating'] = df_filled['Rating'].fillna(df_filled['Rating'].mean())<br>df_filled['BoxOfficeCollection'] = df_filled['BoxOfficeCollection'].fillna(df_filled['BoxOfficeCollection'].mean())<br><br>print(\"\\n After filling missing values with mean:\")<br>print(df_filled.head())<br><br># Handling missing values - Method 3: Fill with median<br>df_median_filled = df_with_missing.copy()<br>df_median_filled['Rating'] = df_median_filled['Rating'].fillna(df_median_filled['Rating'].median())<br>df_median_filled['BoxOfficeCollection'] = df_median_filled['BoxOfficeCollection'].fillna(df_median_filled['BoxOfficeCollection'].median())<br><br>print(\"\\n\ud83d\udcca After filling missing values with median:\")<br>print(df_median_filled.head())<br><br># ============================================<br># Additional EDA - Genre Analysis<br># ============================================<br><br>print(\"\\n\" + \"=\"*60)<br>print(\"Additional Analysis: Genre Insights\")<br>print(\"=\"*60)<br><br># Count movies by genre<br>print(\"\\n Movie Count by Genre:\")<br>print(df['Genre'].value_counts())<br><br># Average rating by genre<br>print(\"\\n Average Rating by Genre:\")<br>print(df.groupby('Genre')['Rating'].mean().sort_values(ascending=False))<br><br># Average box office collection by genre<br>print(\"\\n Average Box Office Collection by Genre:\")<br>print(df.groupby('Genre')['BoxOfficeCollection'].mean().sort_values(ascending=False))<br><br># Visualization - Genre Analysis<br>plt.figure(figsize=(15, 5))<br><br># Subplot 1: Genre distribution<br>plt.subplot(1, 3, 1)<br>genre_counts = df['Genre'].value_counts()<br>plt.pie(genre_counts.values, labels=genre_counts.index, autopct='%1.1f%%', startangle=90)<br>plt.title('Distribution of Movies by Genre')<br><br># Subplot 2: Average rating by genre<br>plt.subplot(1, 3, 2)<br>avg_rating_by_genre = df.groupby('Genre')['Rating'].mean().sort_values()<br>plt.barh(avg_rating_by_genre.index, avg_rating_by_genre.values, color='lightcoral')<br>plt.xlabel('Average Rating')<br>plt.title('Average Rating by Genre')<br>plt.xlim(7, 10)<br><br># Subplot 3: Average collection by genre<br>plt.subplot(1, 3, 3)<br>avg_collection_by_genre = df.groupby('Genre')['BoxOfficeCollection'].mean().sort_values()<br>plt.barh(avg_collection_by_genre.index, avg_collection_by_genre.values, color='lightblue')<br>plt.xlabel('Average Collection (in Crores \u20b9)')<br>plt.title('Average Collection by Genre')<br><br>plt.tight_layout()<br>plt.show()<br><br>print(\"\\n EDA Completed Successfully!\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Create a CSV file named movies.csv with the following attributes: (Movie ID, Title, Genre, Rating, BoxOfficeCollection, Year). Store at least 20 records. Perform EDA # ============================================# Q1. Movie Data Analysis &#8211; EDA# ============================================import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport seaborn as sns# ============================================# Part 1: Create CSV file with Indian Movies# ============================================# [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":188,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,55],"tags":[25,26,59,58,45],"class_list":["post-196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bca","category-ml","tag-bca","tag-bca-paper-solution","tag-machine-learning","tag-ml","tag-python"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":1,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":197,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/196\/revisions\/197"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/188"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}