#优化函数细节
def initial_pic(file_path,column_name,picture_type):
import pandas as pd
import matplotlib.pyplot as plt
#解决字体缺失导致最后出现方框
plt.rcParams['font.family'] = 'SimHei' # 指定使用“黑体”字体,可根据需求选择其他字体
# 读取CSV文件
data = pd.read_csv(file_path)
# 统计不同CommentsStars的元组出现次数
stars_counts = data[column_name].value_counts()
# 绘制统计图
stars_counts.plot(kind=picture_type)
# 设置图表标题和轴标签
plt.title("A statistical graph of the number of occurrences of {} in {} type".format(column_name,picture_type))
# 显示图表
plt.show()
def PrintAll_pic(file_path,column_name):
list=['line','barh','hist','box','kde','area','pie']
for picture_type in list:
initial_pic(file_path,column_name,picture_type)
PrintAll_pic(r"C:\Users\10158\Desktop\Amazon US 评论信息采集.csv",'CommentsStars')