import pandas as pd import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 data = pd.read_csv('movie.csv') data.dropna(inplace=True) # 1.电影时⻓与受欢迎程度的关系分析 x = data x1 = x['duration'] x2 = x['cast_total_facebook_likes'] x2.head() x3 = x['movie_facebook_likes'] plt.scatter(x1,x2) plt.scatter(x1, x3) plt.xlabel('电影时长') plt.legend(('喜爱人数', '点赞人数')) # 2.评分排名前20位的导演 x = data x.sort_values(by='imdb_score', ascending=False).head(20)['director_name'] # 3.拍摄电影数量最多的前10位导演 x = data res = x.groupby('director_name').count().sort_values(by='color', ascending=False).head(10) res.index # 4.票房排名前10位的导演 x = data x.groupby('director_name').sum().sort_values(by='gross', ascending=False).head(10).index # 5.票房排名前5位的男⼀号演员姓名 x = data x.groupby('actor_1_name').sum().sort_values(by='gross', ascending=False).head(5).index # 6.排名前10位最受欢迎的男⼀号演员 x = data x.groupby('actor_1_name').sum().sort_values(by='actor_1_facebook_likes', ascending=False).head(10).index # 7.电影票房的变化趋势 x = data x1 = data['gross'] x2 = data['title_year'] plt.scatter(x2, x1) plt.xlabel('年份') plt.ylabel('票房') # 8.电影票房与电影时⻓的关系分析 x = data x1 = data['gross'] x2 = data['duration'] plt.scatter(x2, x1) plt.xlabel('电影时长') plt.ylabel('票房') # 9.电影评分与电影受欢迎程度分析 x = data x1 = data['imdb_score'] x2 = data['cast_total_facebook_likes'] x3 = data['movie_facebook_likes'] plt.scatter(x1, x2) plt.scatter(x1, x3) plt.xlabel('电影评分') plt.legend(('喜爱人数', '点赞人数')) # 10.电影评分与票房有何关系 x = data x1 = data['imdb_score'] x2 = data['gross'] plt.scatter(x1, x2) plt.xlabel('电影评分') plt.ylabel('票房') # 11.电影出品量前10的排名横向柱状图 x = data res = x.groupby('director_name').count().sort_values(by='color',ascending=False).head(10)['color'] res.plot(kind='barh') # 12.电影出品量变化趋势 x = data x.groupby('title_year').count()['color'].plot(kind='line')