数据来源:https://www.kaggle.com/damianpanek/sunday-eda/data
问题1:获取电影数据中评分的平均分,导演的人数等信息
问题2:获取rating,runtime分布情况
问题3:统计电影分类(genre)情况
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
filePath = "C:\\Users\\dell\\Desktop\\a.csv"
movie = pd.read_csv(filePath)
# 问题1-----------------------
# 获取平均分
movie['Rating'].mean()
# 获取导演人数信息
np.unique(movie['Director']).shape[0]
# 问题2-----------------------
# Rating分布
plt.figure(figsize=(20,8), dpi=100)
plt.hist(movie['Rating'].values, bins=20)
max_ = movie['Rating'].max()
min_ = movie['Rating'].min()
t1 = np.linspace(min_, max_, num=21)
plt.xticks(t1)
plt.grid()
plt.show()
# 问题3-----------------------
# 1、创建一个全为0的DataFrame,列索引置为电影的分类
temp_list = [i.split(',') for i in movie['Genre']]
genre_list = np.unique([i for j in temp_list for i in j])
zeros = np.zeros([movie.shape[0], genre_list.shape[0]])
temp_movie = pd.DataFrame(zeros, columns=genre_list)
# 2、遍历每一部电影,把分类出现的列置为1
for i in range(1000):
temp_movie.loc[i, temp_list[i]] = 1
# 3、求和
genre = temp_movie.sum().sort_values(ascending=False)
genre.plot(kind='bar', figsize=(20,8), fontsize=16)