qxc6bs1pw: 0.0.1 Matplotlib Assignment
qxc6bs1pw: 0.0.1 Matplotlib Assignment
df = pd.read_csv(url)
1. Develop a Line chart using pandas to show how automobile sales fluctuate from year to year
[2]: import matplotlib.pyplot as plt
1
2. Plot different lines for categories of vehicle type and analyze the trend during recession periods
[3]: # Aggregate automobile sales by year and vehicle type
sales_per_year_vehicle = df.groupby(['Year',␣
↪'Vehicle_Type'])['Automobile_Sales'].sum().unstack()
↪label=vehicle_type)
2
3. Visualization to compare the sales trend per vehicle type for recession and non-recession
periods
[4]: # Separate recession and non-recession periods
recession_sales = df[df['Recession'] == 1].groupby(['Year',␣
↪'Vehicle_Type'])['Automobile_Sales'].sum().unstack()
axes[0].set_xlabel('Year')
axes[0].set_ylabel('Automobile Sales')
axes[0].legend(title='Vehicle Type')
axes[0].grid(True)
3
axes[1].set_xlabel('Year')
axes[1].legend(title='Vehicle Type')
axes[1].grid(True)
plt.show()
4. Scatter plot to identify the correlation between average vehicle price and sales volume during
recessions
[5]: # Calculate average price and total sales during recession periods
avg_price_sales_recession = df[df['Recession'] == 1].groupby('Vehicle_Type').
↪agg({'Price': 'mean', 'Automobile_Sales': 'sum'}).reset_index()
# Scatter plot
plt.figure(figsize=(10, 6))
plt.scatter(avg_price_sales_recession['Price'],␣
↪avg_price_sales_recession['Automobile_Sales'])
4
5. Pie chart to display the portion of advertising expenditure of Automotives during recession
and non-recession periods
[6]: # Calculate total advertising expenditure during recession and non-recession␣
↪periods
plt.figure(figsize=(8, 8))
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.
↪1f%%', shadow=True, startangle=140)
5
6) Heatmap to Understand Correlation Between IMDB Score, Hidden Gem Score, and IMDB
Votes
[12]: import pandas as pd
df = pd.read_csv(url)
6
# Ensure relevant columns are numeric
df['IMDb Score'] = pd.to_numeric(df['IMDb Score'], errors='coerce')
df['Hidden Gem Score'] = pd.to_numeric(df['Hidden Gem Score'], errors='coerce')
df['IMDb Votes'] = pd.to_numeric(df['IMDb Votes'], errors='coerce')
7) Plot lines for categories of every movie type and analyze how they have received IMDB Votes.
Create a subplot to compare the same categories with IMDB Score
[17]: # Ensure 'Series or Movie' and 'IMDb Votes' columns are numeric
df['IMDb Votes'] = pd.to_numeric(df['IMDb Votes'], errors='coerce')
7
df['IMDb Score'] = pd.to_numeric(df['IMDb Score'], errors='coerce')
# Create subplots
fig, axes = plt.subplots(1, 2, figsize=(16, 6))
plt.tight_layout()
plt.show()
8) Create 2 bar plots to understand movies and web series by languages in which they have been
made
8
[ ]: # Extract languages data for movies and web series
movie_languages = df[df['Series or Movie'] == 'Movie']['Languages'].
↪value_counts().reset_index()
# Movies by language
sns.barplot(ax=axes[0], data=movie_languages.head(10), x='Count', y='Language',␣
↪hue='Language', palette='viridis', dodge=False, legend=False)
plt.tight_layout()
plt.show()