import csv
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pandas as pd
import random
#导入
data_df=pd.read_excel('douban_top250.xlsx')
#清洗
rows_with_na=data_df[data_df.isnull().values]
cleaned=data_df.dropna()
#保存
cleaned.to_excel('cleaned_top250.xlsx', index=False)
data2_df=pd.read_excel('cleaned_top250.xlsx')
print(data2_df.describe())
print(data2_df.info())
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None) # 注意这里是max_rows,不是max_row
pd.set_option('display.width', None)
plt.rcParams['font.sans-serif'] = ['SimHei']
#显示全部列
pd.set_option('display.max_columns', None)
#显示全部行
pd.set_option('display.max_row', None)
#设置数据的显示长度(解决自动换行)
pd.set_option('display.width', None)
# 中文乱码
plt.rcParams['font.sans-serif']=['SimHei']
# 设置画布大小
plt.figure(figsize=(10, 6))
# 设置网格线
plt.grid(axis='y', linestyle=':')
# 读表
df = pd.read_excel('cleaned_top250.xlsx')
df_mov=df.head(10)
df_select=df_mov['电影中文名']
x = df_mov['电影中文名']
y = df_mov['评分']
# 设置标签
plt.xlabel('电影中文名')
plt.ylabel('评分')
plt.title('学号加姓名电影评分', fontsize=18)
# 设置文本标签
for a, b in zip(x, y):
plt.text(a, b, format(b, ','), ha='center', va='bottom', alpha=0.9)
plt.bar(x, y, alpha=0.5, label='评分')
# 设置图例
plt.legend()
plt.show()
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None) # 注意这里是max_rows,不是max_row
pd.set_option('display.width', None)
plt.rcParams['font.sans-serif'] = ['SimHei']
df = pd.read_excel('cleaned_top250.xlsx')
director_counts = df['导演'].value_counts().reset_index()
director_counts.columns = ['导演', '电影数量']
top4_directors = director_counts.nlargest(4, '电影数量')
print(top4_directors)
plt.figure(figsize=(10, 6))
plt.bar(top4_directors['导演'], top4_directors['电影数量'], alpha=0.5)
plt.xlabel('导演')
plt.ylabel('上榜电影数量')
plt.title('学号加姓名前四位导演上榜电影数量', fontsize=18)
for index, row in top4_directors.iterrows():
plt.text(row['导演'], row['电影数量'], str(row['电影数量']), ha='center', va='bottom', alpha=0.9)
plt.grid(axis='y', linestyle=':')
plt.show()
pd.set_option('display.max_columns', None)
#显示全部行
pd.set_option('display.max_row', None)
#设置数据的显示长度(解决自动换行)
pd.set_option('display.width', None)
# 中文乱码
plt.rcParams['font.sans-serif']=['SimHei']
# 设置画布大小
plt.figure(figsize=(10, 6))
# 设置网格线
plt.grid(axis='x', linestyle=':')
# 读表
df = pd.read_excel('cleaned_top250.xlsx')
df_mov=df.head(10)
df_select=df_mov['电影中文名']
x = df_mov['电影中文名']
y = df_mov['评分人数']
# 设置标签
plt.xlabel('电影中文名')
plt.ylabel('评分人数')
plt.title('学号电影评分人数', fontsize=18)
# 设置文本标签
for a, b in zip(x, y):
plt.text(a, b, format(b, ','), ha='center', va='bottom', alpha=0.9)
plt.plot(x, y, alpha=0.5, label='评分人数')
# 设置图例
plt.legend()
plt.show()
数据可视化
于 2024-06-10 23:40:49 首次发布