From e999f1ead95ad0df45bf38ebc3d81d50743adb13 Mon Sep 17 00:00:00 2001 From: Maxxxxxxxx1 Date: Wed, 20 Dec 2023 07:25:32 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9C=9F=E6=9C=AB=E4=BD=9C=E4=B8=9A-=E4=BD=99?= =?UTF-8?q?=E4=BF=8A=E4=B8=BD-=E8=8E=AB=E6=9F=AF=E6=9E=97-=E5=80=99?= =?UTF-8?q?=E7=A5=96=E8=BE=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxxxxxxxx1 --- ...7-\345\200\231\347\245\226\350\276\211.py" | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 "\346\234\237\346\234\253\344\275\234\344\270\232-\344\275\231\344\277\212\344\270\275-\350\216\253\346\237\257\346\236\227-\345\200\231\347\245\226\350\276\211.py" diff --git "a/\346\234\237\346\234\253\344\275\234\344\270\232-\344\275\231\344\277\212\344\270\275-\350\216\253\346\237\257\346\236\227-\345\200\231\347\245\226\350\276\211.py" "b/\346\234\237\346\234\253\344\275\234\344\270\232-\344\275\231\344\277\212\344\270\275-\350\216\253\346\237\257\346\236\227-\345\200\231\347\245\226\350\276\211.py" new file mode 100644 index 0000000..a3d9f04 --- /dev/null +++ "b/\346\234\237\346\234\253\344\275\234\344\270\232-\344\275\231\344\277\212\344\270\275-\350\216\253\346\237\257\346\236\227-\345\200\231\347\245\226\350\276\211.py" @@ -0,0 +1,144 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri May 19 11:46:02 2023 + +@author: Max +绘制随机用户播放量散点图 +""" + +import pandas as pd +import numpy as np +import matplotlib.pyplot as plt +#先处理一下useraction: +#这是用户信息表 +df_r = pd.read_csv('C:/Users/MAX/Desktop/rawdata.csv',header=1) +#设置一下行名 +df_r.columns = ['Year', 'Industry', 'Industry_A', 'Country', 'Country_A','Installation','OperationalStock'] +#让我们看看用户播放的有没有啥规律 +df_r=df_r.replace(0,np.nan) +df = df_r[df_r.loc[:]!=0].dropna() +df=df[['Year','Industry_A','Country_A','Installation','OperationalStock']] +df2=df[['Year','Industry_A','Country_A','Installation','OperationalStock']] +# print(df.info()) +print(df['Country_A'].value_counts()) +print(df['Industry_A'].value_counts()) +Continents=['WORLD','ASIA/AUSTRALIA','South East Asia','EUROPE','Western Europe','AMERICA','North America', + 'Other Asia', 'Europe unspecified','America, not specified','Central/Eastern Europe' + 'AFRICA','Rest of Europe', 'Rest of South America' 'all other European countries' 'South America', + 'Rest of Asia','other South/East Asia','other Eastern Europe','Rest of Africa', 'Others not specified' 'Other Africa' ,] +i=0 +for i in range(0,len(Continents)): + print('删除'+Continents[i]) + df=df.drop(df[df["Country_A"]==Continents[i]].index) + i+1 +df=df.reset_index(drop="True") +df.info() +df.to_csv('C:/Users/MAX/Desktop/data1.csv') +df_all=df.loc[df['Industry_A']=='All Industries'] +df_all=df_all.reset_index(drop="True") +print(df_all.info()) +df_all=df_all[['Year','Country_A','Installation','OperationalStock']] +df_all.to_csv('C:/Users/MAX/Desktop/data_all.csv') + +for i in range(1993,2020): + df_i=df_all.loc[df_all['Year']==i] + df_i=df_i.sort_values(by="Installation",ascending=False).head(5) + print(df_i) + a=df_i['Country_A'] + + height = 0.2 + a1 = list(range(len(a))) + a2 = [i+height for i in a1]#坐标轴偏移 + a3 = [i+height*2 for i in a1] + + #绘图 + plt.barh(range(len(a)),df_i['Installation'],height= height,label = "Installation",color = "#FFC125") + plt.barh(a2,df_i['OperationalStock'],height= height,label = 'OperationalStock',color = "#969696") + + #绘制网格 + plt.grid(alpha = 0.4) + + #y轴坐标刻度标识 + plt.yticks(a2,a,fontsize = 14) + + #添加图例 + plt.legend() + + #添加横纵坐标,标题 + plt.xlabel("Number",fontsize = 16) + plt.title("%d year World Industrial Robot"%i,fontsize = 24) + + #显示图形 + plt.show() + + +df_c=df_all[df_all['Country_A']=='China'] +print(df_c) +#画图 +x=np.array(df_c['Year']) +y1=np.array(df_c['Installation']) +y2=np.array(df_c['OperationalStock']) +plt.plot(x,y1, 'b*--', alpha=0.5, linewidth=1, label='Installation')#' +plt.plot(x,y2, 'rs--', alpha=0.5, linewidth=1, label='OperationalStock') + + +plt.legend() #显示上面的label +plt.xlabel('Year',fontsize = 16) +plt.ylabel('number')#accuracy + + +plt.show() + + + +Continent=['WORLD','ASIA/AUSTRALIA','South East Asia','EUROPE','AMERICA'] +for c in Continent: + # 筛选特定国家的数据 + continent_data = df2[df2["Country_A"] == c] + continent_data=continent_data.loc[continent_data['Industry_A']=='All Industries'] + continent_data=continent_data.reset_index(drop="True") + # 按时间排序 + continent_data = continent_data.sort_values("Year") + x=np.array(continent_data['Year']) + y=np.array(continent_data['OperationalStock']) + + # 绘制折线图 + plt.plot(x, y, label=c) + # 设置图例 +plt.legend() +plt.xlabel('Year') +plt.ylabel('OperationalStock') +plt.title('OperationalStock Variation for Each Country over Time') +plt.show() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- Gitee