# ========================================
# ЗАДАНИЕ 1
# ========================================
movies_2016 = df[df['Year'] == 2016]
plt.hist(movies_2016['Metascore'].dropna(), bins=20)
plt.xlabel('Metascore')
plt.ylabel('Количество фильмов')
plt.title('Metascore фильмов 2016 года')
plt.grid(True)
plt.show()
sns.kdeplot(movies_2016['Metascore'].dropna(), fill=True)
plt.xlabel('Metascore')
plt.title('Плотность распределения Metascore фильмов 2016 года')
plt.grid(True)
plt.show()
# ========================================
# ЗАДАНИЕ 2
# ========================================
plt.scatter(df['Votes'], df['Rating'])
plt.xlabel('Количество голосов')
plt.ylabel('Рейтинг')
plt.title('Зависимость рейтинга от количества голосов')
plt.grid(True)
plt.show()
# ========================================
# ЗАДАНИЕ 3
# ========================================
comedies = df[df['Genre'].str.contains('Comedy')]
thrillers = df[df['Genre'].str.contains('Thriller')]
sns.kdeplot(comedies['Rating'], label='Comedy', fill=True, alpha=0.3)
sns.kdeplot(thrillers['Rating'], label='Thriller', fill=True, alpha=0.3)
plt.xlabel('Рейтинг')
plt.ylabel('Плотность')
plt.title('Сравнение рейтингов комедий и триллеров')
plt.legend()
plt.grid(True)
plt.show()
# ========================================
# ЗАДАНИЕ 4
# ========================================
movies_2010_2016 = df[
(df['Year'] >= 2010) &
(df['Year'] <= 2016) &
(
df['Genre'].str.contains('Horror') |
df['Genre'].str.contains('Family')
)
].copy()
movies_2010_2016['Genre_group'] = 'Other'
movies_2010_2016.loc[
movies_2010_2016['Genre'].str.contains('Horror'),
'Genre_group'
] = 'Horror'
movies_2010_2016.loc[
movies_2010_2016['Genre'].str.contains('Family'),
'Genre_group'
] = 'Family'
sns.countplot(
data=movies_2010_2016,
x='Year',
hue='Genre_group',
hue_order=['Horror', 'Family']
)
plt.xlabel('Год')
plt.ylabel('Количество фильмов')
plt.title('Количество фильмов ужасов и семейных фильмов')
plt.grid(True)
plt.show()