1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| import pandas as pd import matplotlib.pyplot as plt plt.rcParams['font.family'] = 'SimHei'
data_frame = pd.DataFrame(pd.read_csv('2018世界杯球队数据.csv',encoding='gbk')) data_frame_1 = data_frame.loc[:,['球队','进球','失球']] data_frame_1_win_goal = data_frame_1['进球'] - data_frame_1['失球'] data_frame_1['净胜球'] = data_frame_1_win_goal data_frame_1 = data_frame_1[data_frame_1.净胜球 >0] data_frame_1_final = data_frame_1.loc[:,['球队','净胜球']] data_frame_1_name = data_frame_1_final['球队'].values print('净胜球大于0的球队有:',end='') for i in data_frame_1_name: print(i,end=' ')
data_frame_2 = data_frame.loc[:,['球队','红牌']] data_frame_2 = data_frame_2[data_frame_2.红牌 > 0].values print('被罚红牌的队伍有:') for i in data_frame_2: print(i[0],end=' ')
data_frame_3 = data_frame.loc[:,['球队','进球','射门']] data_frame_3_goalrate = data_frame_3['进球'] / data_frame_3['射门']*100 data_frame_3['进球率'] = data_frame_3_goalrate data_frame_3 = data_frame_3[data_frame_3.进球率 > 10] data_frame_3.drop(labels='进球率',axis=1,inplace=True) print(data_frame_3)
data_frame_4 = data_frame.loc[:,['球队','进球','黄牌']] data_frame_4_TotalGoalAverage = data_frame_4['进球'].mean()
data_frame_4 = data_frame_4[(data_frame_4.进球 > data_frame_4_TotalGoalAverage) & (data_frame_4.黄牌 < 5)] print(data_frame_4)
data_frame_5 = data_frame.loc[:,['球队','进球']] data_frame_5.sort_values(by='进球',ascending=False,inplace=True) print(data_frame_5)
data_frame_6 = data_frame.loc[:,['所属洲','进球']] data_frame_6_final = data_frame_6.groupby('所属洲').sum() data_frame_6_final.sort_values(by='进球',inplace=True) print(data_frame_6_final)
data_frame_7 = data_frame.loc[:,['所属洲','进球']] data_frame_7_final = data_frame_7.groupby('所属洲').sum() data_frame_7_final.plot.bar() plt.title('各大洲进球数') plt.show()
data_frame_8 = data_frame.loc[:,['所属洲','球队','进球','抢断','射门']] data_frame_8 = data_frame_8[data_frame_8.所属洲 == '欧洲'] data_frame_8_bar = data_frame_8.loc[:,['球队','进球']] data_frame_8_pie = data_frame_8.loc[:,['球队','抢断']] data_frame_8_plot = data_frame_8.loc[:,['球队','射门']]
plt.subplot(221) plt.title('欧洲球队抢断数') plt.scatter(data_frame_8_pie['抢断'],data_frame_8_pie['球队']) plt.subplot(222) plt.title('欧洲球队射门次数占比') plt.pie(data_frame_8_plot['射门'],labels=data_frame_8_plot['球队']) plt.subplot(212) plt.title('欧洲球队进球数') plt.bar(data_frame_8_bar['球队'],data_frame_8_bar['进球']) plt.show()
|