From 944606fe3647bd1818b44c3a32b30f09aeb28694 Mon Sep 17 00:00:00 2001 From: hnu202410040206 Date: Thu, 22 May 2025 16:04:23 +0800 Subject: [PATCH] ADD file via upload --- DataAnalysis3.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 DataAnalysis3.py diff --git a/DataAnalysis3.py b/DataAnalysis3.py new file mode 100644 index 0000000..69d2d2c --- /dev/null +++ b/DataAnalysis3.py @@ -0,0 +1,38 @@ +import pandas as pd +import matplotlib.pyplot as plt + +# 加载数据 +df = pd.read_csv('/mnt/豆瓣电影_20250510_173909.csv') + +# 统计不同导演的作品数量 +director_counts = df['导演'].value_counts() + +# 找出作品数量前五的导演 +top_five_directors = director_counts.nlargest(5, keep='all') + +# 设置图片清晰度 +plt.rcParams['figure.dpi'] = 300 + +# 设置中文字体 +plt.rcParams['font.sans-serif'] = ['WenQuanYi Zen Hei'] + +# 绘制柱状图 +plt.figure(figsize=(10, 6)) +bars = top_five_directors.plot(kind='bar') + +# 添加数据标签 +for bar in bars.patches: + height = bar.get_height() + plt.text(bar.get_x() + bar.get_width() / 2, height, str(int(height)), ha='center', va='bottom') + +# 设置图表标题和坐标轴标签 +plt.title('作品数量前五的导演') +plt.xlabel('导演') +plt.ylabel('作品数量') +plt.xticks(rotation=45) + +# 显示图形 +plt.show() + +print('作品数量前五的导演:') +print(top_five_directors) \ No newline at end of file