数据可视化

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值