File size: 19,222 Bytes
8eea1d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
import streamlit as st

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
import warnings

warnings.filterwarnings('ignore')


# In[90]:


# In[91]:

def main():
    st.title("FIFA Data visualization")


df = pd.read_csv('./data/international_matches.csv', parse_dates=['date'])
# df.tail()
#

# In[92]:


# df.columns


# In[93]:


# df.isnull().sum()


# # PRE-ANALYSIS
# The dataset has a lot of blank fields that need to be fixed.
# However, before modifying any field, I want to analyze the teams' qualifications on the last FIFA date (June 2022). This is important because, from these qualifications, I will create the inference dataset that enters the machine learning algorithm that predicts the World Cup matches.

# ### Top 10 FIFA Ranking
# Top 10 national teams to date FIFA June 2022.
# **ref:** https://www.fifa.com/fifa-world-ranking/men?dateId=id13603


# In[94]:


fifa_rank = df[['date', 'home_team', 'away_team', 'home_team_fifa_rank', 'away_team_fifa_rank']]
home = fifa_rank[['date', 'home_team', 'home_team_fifa_rank']].rename(
    columns={"home_team": "team", "home_team_fifa_rank": "rank"})
away = fifa_rank[['date', 'away_team', 'away_team_fifa_rank']].rename(
    columns={"away_team": "team", "away_team_fifa_rank": "rank"})
fifa_rank = pd.concat([home, away])
# Select each country latest match
fifa_rank = fifa_rank.sort_values(['team', 'date'], ascending=[True, False])
last_rank = fifa_rank
fifa_rank_top10 = fifa_rank.groupby('team').first().sort_values('rank', ascending=True)[0:10].reset_index()


# fifa_rank_top10


# ### Top 10 teams with the highest winning percentage at home and away

# In[95]:


def home_percentage(team):
    score = len(df[(df['home_team'] == team) & (df['home_team_result'] == "Win")]) / len(
        df[df['home_team'] == team]) * 100
    return round(score)


def away_percentage(team):
    score = len(df[(df['away_team'] == team) & (df['home_team_result'] == "Lose")]) / len(
        df[df['away_team'] == team]) * 100
    return round(score)


# In[96]:


fifa_rank_top10['Home_win_Per'] = np.vectorize(home_percentage)(fifa_rank_top10['team'])
fifa_rank_top10['Away_win_Per'] = np.vectorize(away_percentage)(fifa_rank_top10['team'])
fifa_rank_top10['Average_win_Per'] = round((fifa_rank_top10['Home_win_Per'] + fifa_rank_top10['Away_win_Per']) / 2)
fifa_rank_win = fifa_rank_top10.sort_values('Average_win_Per', ascending=False)
# fifa_rank_win


# ### Top 10 attacking teams in the last FIFA date

# In[97]:


fifa_offense = df[['date', 'home_team', 'away_team', 'home_team_mean_offense_score', 'away_team_mean_offense_score']]
home = fifa_offense[['date', 'home_team', 'home_team_mean_offense_score']].rename(
    columns={"home_team": "team", "home_team_mean_offense_score": "offense_score"})
away = fifa_offense[['date', 'away_team', 'away_team_mean_offense_score']].rename(
    columns={"away_team": "team", "away_team_mean_offense_score": "offense_score"})
fifa_offense = pd.concat([home, away])
fifa_offense = fifa_offense.sort_values(['date', 'team'], ascending=[False, True])
last_offense = fifa_offense
fifa_offense_top10 = fifa_offense.groupby('team').first().sort_values('offense_score', ascending=False)[
                     0:10].reset_index()
# fifa_offense_top10

import plotly.graph_objs as go
import plotly.figure_factory as ff

# In[99]:

# Display the data for the bar chart
st.write("Top 10 Attacking Teams")
st.write(fifa_offense_top10)

# Create a horizontal bar chart
fig_bar = go.Figure(data=[go.Bar(y=fifa_offense_top10['team'], x=fifa_offense_top10['offense_score'], orientation='h')])
# Update layout to include title, x-label, and y-label
fig_bar.update_layout(title='Top 10 Attacking Teams',
                      xaxis_title='Offense Score',
                      yaxis_title='Team')
st.plotly_chart(fig_bar)

# Display the data for the bar chart
# st.write("Top 10 Offense Teams")
# st.write(fifa_offense_top10)

# sns.barplot(data=fifa_offense_top10, x='offense_score', y='team', color="#7F1431")
# plt.xlabel('Offense Score', size = 20)
# plt.ylabel('Team', size = 20)
# plt.title("Top 10 Attacking teams");


# ### Top 10 Midfield teams in the last FIFA date

# In[100]:


fifa_midfield = df[['date', 'home_team', 'away_team', 'home_team_mean_midfield_score', 'away_team_mean_midfield_score']]
home = fifa_midfield[['date', 'home_team', 'home_team_mean_midfield_score']].rename(
    columns={"home_team": "team", "home_team_mean_midfield_score": "midfield_score"})
away = fifa_midfield[['date', 'away_team', 'away_team_mean_midfield_score']].rename(
    columns={"away_team": "team", "away_team_mean_midfield_score": "midfield_score"})
fifa_midfield = pd.concat([home, away])
fifa_midfield = fifa_midfield.sort_values(['date', 'team'], ascending=[False, True])
last_midfield = fifa_midfield
fifa_midfield_top10 = fifa_midfield.groupby('team').first().sort_values('midfield_score', ascending=False)[
                      0:10].reset_index()
# fifa_midfield_top10


# In[101]:

# Display the data for the bar chart
st.write("Top 10 Midfield Teams")
st.write(fifa_midfield_top10)

# Create a horizontal bar chart
fig_bar = go.Figure(
    data=[go.Bar(y=fifa_midfield_top10['team'], x=fifa_midfield_top10['midfield_score'], orientation='h')])
# Update layout to include title, x-label, and y-label
fig_bar.update_layout(title='Top 10 Midfield Teams',  # Set the title
                      xaxis_title='Midfield Score',  # Set the x-axis label
                      yaxis_title='Team')  # Set the y-axis label

# Display the bar chart
st.plotly_chart(fig_bar)

# sns.barplot(data=fifa_midfield_top10, x='midfield_score', y='team', color="#7F1431")
# plt.xlabel('Midfield Score', size = 20)
# plt.ylabel('Team', size = 20)
# plt.title("Top 10 Midfield teams");


# ### Top 10 defending teams in the last FIFA date

# In[102]:


fifa_defense = df[['date', 'home_team', 'away_team', 'home_team_mean_defense_score', 'away_team_mean_defense_score']]
home = fifa_defense[['date', 'home_team', 'home_team_mean_defense_score']].rename(
    columns={"home_team": "team", "home_team_mean_defense_score": "defense_score"})
away = fifa_defense[['date', 'away_team', 'away_team_mean_defense_score']].rename(
    columns={"away_team": "team", "away_team_mean_defense_score": "defense_score"})
fifa_defense = pd.concat([home, away])
fifa_defense = fifa_defense.sort_values(['date', 'team'], ascending=[False, True])
last_defense = fifa_defense
fifa_defense_top10 = fifa_defense.groupby('team').first().sort_values('defense_score', ascending=False)[
                     0:10].reset_index()
# fifa_defense_top10


# In[103]:

# Display the data for the bar chart
st.write("Top 10 Defensive Teams")
st.write(fifa_defense_top10)

# Create the horizontal bar chart
fig_bar = go.Figure(data=[go.Bar(y=fifa_defense_top10['team'], x=fifa_defense_top10['defense_score'], orientation='h')])

# Update layout to include title, x-label, and y-label
fig_bar.update_layout(title='Top 10 Defensive Teams',  # Set the title
                      xaxis_title='Defense Score',  # Set the x-axis label
                      yaxis_title='Team')  # Set the y-axis label

# Display the bar chart
st.plotly_chart(fig_bar)

sns.barplot(data=fifa_defense_top10, x='defense_score', y='team', color="#7F1431")
plt.xlabel('Defense Score', size=20)
plt.ylabel('Team', size=20)
plt.title("Top 10 Defense Teams")

# ### Do Home teams have any advantage?

# In[104]:


# Select all matches played at non-neutral locations
home_team_advantage = df[df['neutral_location'] == False]['home_team_result'].value_counts(normalize=True)

# # Plot
# fig, axes = plt.subplots(1, 1, figsize=(8,8))
# ax =plt.pie(home_team_advantage  ,labels = ['Win', 'Lose', 'Draw'], autopct='%.0f%%')
# plt.title('Home team match result', fontsize = 15)
# plt.show()


# As the graph shows, the home team has an advantage over the away team. This is due to factors such as the fans, the weather and the confidence of the players. For this reason, in the World Cup, those teams that sit at home will have an advantage.

# # DATA PREPARATION AND FEATURE ENGINEERING
# In this section, I will fill in the empty fields in the dataset and clean up the data for teams that did not qualify for the World Cup. Then, I will use the correlation matrix to choose the characteristics that will define the training dataset of the Machine Learning model. Finally, I will use the ratings of the teams in their last match to define the "Last Team Scores" dataset (i.e., the dataset that I will use to predict the World Cup matches).

# ### Analyze and fill na's

# In[105]:

#
# df.isnull().sum()


# In[106]:


# We can fill mean for na's in goal_keeper_score
df[df['home_team'] == "Brazil"]['home_team_goalkeeper_score'].describe()

# In[107]:


df['home_team_goalkeeper_score'] = round(
    df.groupby("home_team")["home_team_goalkeeper_score"].transform(lambda x: x.fillna(x.mean())))
df['away_team_goalkeeper_score'] = round(
    df.groupby("away_team")["away_team_goalkeeper_score"].transform(lambda x: x.fillna(x.mean())))

# In[108]:


# We can fill mean for na's in defense score
df[df['away_team'] == "Uruguay"]['home_team_mean_defense_score'].describe()

# In[65]:


df['home_team_mean_defense_score'] = round(
    df.groupby('home_team')['home_team_mean_defense_score'].transform(lambda x: x.fillna(x.mean())))
df['away_team_mean_defense_score'] = round(
    df.groupby('away_team')['away_team_mean_defense_score'].transform(lambda x: x.fillna(x.mean())))

# In[109]:


# We can fill mean for na's in offense score
df[df['away_team'] == "Uruguay"]['home_team_mean_offense_score'].describe()

# In[67]:


df['home_team_mean_offense_score'] = round(
    df.groupby('home_team')['home_team_mean_offense_score'].transform(lambda x: x.fillna(x.mean())))
df['away_team_mean_offense_score'] = round(
    df.groupby('away_team')['away_team_mean_offense_score'].transform(lambda x: x.fillna(x.mean())))

# In[110]:


# We can fill mean for na's in midfield score
df[df['away_team'] == "Uruguay"]['home_team_mean_midfield_score'].describe()

# In[111]:


df['home_team_mean_midfield_score'] = round(
    df.groupby('home_team')['home_team_mean_midfield_score'].transform(lambda x: x.fillna(x.mean())))
df['away_team_mean_midfield_score'] = round(
    df.groupby('away_team')['away_team_mean_midfield_score'].transform(lambda x: x.fillna(x.mean())))

# In[112]:


df.isnull().sum()

# In[113]:


# Teams are not available in FIFA game itself, so they are not less than average performing teams, so giving a average score of 50 for all.
df.fillna(50, inplace=True)

# ### Filter the teams participating in QATAR - World cup 2022

# In[115]:


list_2022 = ['Qatar', 'Germany', 'Denmark', 'Brazil', 'France', 'Belgium', 'Croatia', 'Spain', 'Serbia', 'England',
             'Switzerland', 'Netherlands', 'Argentina', 'IR Iran', 'Korea Republic', 'Japan', 'Saudi Arabia', 'Ecuador',
             'Uruguay', 'Canada', 'Ghana', 'Senegal', 'Portugal', 'Poland', 'Tunisia', 'Morocco', 'Cameroon', 'USA',
             'Mexico', 'Wales', 'Australia', 'Costa Rica']
final_df = df[(df["home_team"].apply(lambda x: x in list_2022)) | (df["away_team"].apply(lambda x: x in list_2022))]

# **Top 10 teams in QATAR 2022**

# In[116]:


rank = final_df[['date', 'home_team', 'away_team', 'home_team_fifa_rank', 'away_team_fifa_rank']]
home = rank[['date', 'home_team', 'home_team_fifa_rank']].rename(
    columns={"home_team": "team", "home_team_fifa_rank": "rank"})
away = rank[['date', 'away_team', 'away_team_fifa_rank']].rename(
    columns={"away_team": "team", "away_team_fifa_rank": "rank"})
rank = pd.concat([home, away])

# Select each country latest match
rank = rank.sort_values(['team', 'date'], ascending=[True, False])
rank_top10 = rank.groupby('team').first().sort_values('rank', ascending=True).reset_index()
rank_top10 = rank_top10[(rank_top10["team"].apply(lambda x: x in list_2022))][0:10]

st.write("Top 10 Countries by Rank - Latest Match")
rank_top10

# # Create a scatter plot
# fig_scatter = go.Figure(data=go.Scatter(x=rank_top10['team'], y=rank_top10['rank'], mode='markers', marker=dict(color='lightskyblue', size=12)))
#
# # Update layout to include title and labels
# fig_scatter.update_layout(title='Top 10 Countries by Rank - Latest Match',
#                           xaxis_title='Country',
#                           yaxis_title='Rank')
#
# # Display the scatter plot
# st.plotly_chart(fig_scatter)

# **Top 10 teams with the highest winning percentage in QATAR 2022**

# In[117]:


rank_top10['Home_win_Per'] = np.vectorize(home_percentage)(rank_top10['team'])
rank_top10['Away_win_Per'] = np.vectorize(away_percentage)(rank_top10['team'])
rank_top10['Average_win_Per'] = round((rank_top10['Home_win_Per'] + rank_top10['Away_win_Per']) / 2)
rank_top10_Win = rank_top10.sort_values('Average_win_Per', ascending=False)

# st.write("Top 10 Countries by Rank - Latest Match")
# rank_top10_Win


# In[118]:

# Display the data for the bar chart
st.write("Top 10 Average Win Per game Teams")
st.write(rank_top10_Win)

# Create a horizontal bar chart
# Create a horizontal bar chart
fig_bar = go.Figure(data=[go.Bar(y=rank_top10_Win['team'], x=rank_top10_Win['Average_win_Per'], orientation='h')])

# Update layout to include title and labels
fig_bar.update_layout(title='Top 10 Countries by Average Win Percentage',
                      xaxis_title='Average Win Percentage',
                      yaxis_title='Country')

# Display the horizontal bar chart
st.plotly_chart(fig_bar)

# sns.barplot(data=rank_top10_Win,x='Average_win_Per',y='team',color="#7F1431")
# plt.xticks()
# plt.xlabel('Win Average', size = 20)
# plt.ylabel('Team', size = 20)
# plt.title('Top 10 QATAR 2022 teams with the highest winning percentage')

#
# # ### Correlation Matrix
#
# # In[124]:
#
#
# final_df['home_team_result'].values
# # for index, value in final_df['home_team_result'].items():
# #     print(f"Row {index}: {value}")
#
#
# # In[125]:
#
#
# team_result_df = final_df
# # for index, value in team_result_df['home_team_result'].items():
# #     print(f"Row {index}: {value}")
#
#
# # In[151]:
#
#
# # Mapping numeric values for home_team_result to find the correleations
# final_df['home_team_result'] = final_df['home_team_result'].map({'Win':1, 'Draw':2, 'Lose':0})
#
#
# # In[145]:
#
#
#
#
#
# # In[150]:
#
#
# final_df['home_team_result'].head(1)
#
#
# # In[152]:
#
#
# final_df['home_team_result'] = pd.to_numeric(final_df['home_team_result'], errors='coerce')
#
#
# # In[155]:
#
#
# # df.head()
#
#
# # In[156]:
#
#
# # final_df.head()
#
#
# # In[157]:
#
#
# numerical_df = final_df.select_dtypes(include=['number'])
#
#
# # In[158]:
#
#
# numerical_df.corr()['home_team_result'].sort_values(ascending=False)
#
#
# # In[153]:
#
#
# # final_df.corr()['home_team_result'].sort_values(ascending=False)
#
#
# # Dropping unnecessary colums.
#
# # In[ ]:
#
#
# #Dropping unnecessary colums
# final_df = final_df.drop(['date', 'home_team_continent', 'away_team_continent', 'home_team_total_fifa_points', 'away_team_total_fifa_points', 'home_team_score', 'away_team_score', 'tournament', 'city', 'country', 'neutral_location', 'shoot_out'],axis=1)
#
#
# # In[ ]:
#
#
# # final_df.columns
#
#
# # In[ ]:
#
#
# # Change column names
# final_df.rename(columns={"home_team":"Team1", "away_team":"Team2", "home_team_fifa_rank":"Team1_FIFA_RANK",
#                          "away_team_fifa_rank":"Team2_FIFA_RANK", "home_team_result":"Team1_Result", "home_team_goalkeeper_score":"Team1_Goalkeeper_Score",
#                         "away_team_goalkeeper_score":"Team2_Goalkeeper_Score", "home_team_mean_defense_score":"Team1_Defense",
#                         "home_team_mean_offense_score":"Team1_Offense", "home_team_mean_midfield_score":"Team1_Midfield",
#                         "away_team_mean_defense_score":"Team2_Defense", "away_team_mean_offense_score":"Team2_Offense",
#                         "away_team_mean_midfield_score":"Team2_Midfield"}, inplace=True)
#
#
# # In[ ]:
#
#
# plt.figure(figsize=(10, 4), dpi=200)
# sns.heatmap(final_df.corr(), annot=True)
#
#
# # In[ ]:
#
#
# # final_df.info()
#
#
# # In[ ]:
#
#
# # final_df
#
#
# # Exporting the training dataset.
#
# # In[ ]:
#
#
# # final_df.to_csv("./data/training.csv", index = False)
#
#
# # ### Creating "Last Team Scores" dataset
# # This dataset contains the qualifications of each team on the previous FIFA date and will be used to predict the World Cup matches.
#
# # In[ ]:
#
#
# last_goalkeeper = df[['date', 'home_team', 'away_team', 'home_team_goalkeeper_score', 'away_team_goalkeeper_score']]
# home = last_goalkeeper[['date', 'home_team', 'home_team_goalkeeper_score']].rename(columns={"home_team":"team", "home_team_goalkeeper_score":"goalkeeper_score"})
# away = last_goalkeeper[['date', 'away_team', 'away_team_goalkeeper_score']].rename(columns={"away_team":"team", "away_team_goalkeeper_score":"goalkeeper_score"})
# last_goalkeeper = pd.concat([home,away])
#
# last_goalkeeper = last_goalkeeper.sort_values(['date', 'team'],ascending=[False, True])
#
# list_2022 = ['Qatar', 'Germany', 'Denmark', 'Brazil', 'France', 'Belgium', 'Croatia', 'Spain', 'Serbia', 'England', 'Switzerland', 'Netherlands', 'Argentina', 'IR Iran', 'Korea Republic', 'Japan', 'Saudi Arabia', 'Ecuador', 'Uruguay', 'Canada', 'Ghana', 'Senegal', 'Portugal', 'Poland', 'Tunisia', 'Morocco', 'Cameroon', 'USA', 'Mexico', 'Wales', 'Australia', 'Costa Rica']
#
# rank_qatar = last_rank[(last_rank["team"].apply(lambda x: x in list_2022))]
# rank_qatar = rank_qatar.groupby('team').first().reset_index()
# goal_qatar = last_goalkeeper[(last_goalkeeper["team"].apply(lambda x: x in list_2022))]
# goal_qatar = goal_qatar.groupby('team').first().reset_index()
# goal_qatar = goal_qatar.drop(['date'], axis = 1)
# off_qatar = last_offense[(last_offense["team"].apply(lambda x: x in list_2022))]
# off_qatar = off_qatar.groupby('team').first().reset_index()
# off_qatar = off_qatar.drop(['date'], axis = 1)
# mid_qatar = last_midfield[(last_midfield["team"].apply(lambda x: x in list_2022))]
# mid_qatar = mid_qatar.groupby('team').first().reset_index()
# mid_qatar = mid_qatar.drop(['date'], axis = 1)
# def_qatar = last_defense[(last_defense["team"].apply(lambda x: x in list_2022))]
# def_qatar = def_qatar.groupby('team').first().reset_index()
# def_qatar = def_qatar.drop(['date'], axis = 1)
#
# qatar = pd.merge(rank_qatar, goal_qatar, on = 'team')
# qatar = pd.merge(qatar, def_qatar, on ='team')
# qatar = pd.merge(qatar, off_qatar, on ='team')
# qatar = pd.merge(qatar, mid_qatar, on ='team')
#
# qatar['goalkeeper_score'] = round(qatar["goalkeeper_score"].transform(lambda x: x.fillna(x.mean())))
# qatar['offense_score'] = round(qatar["offense_score"].transform(lambda x: x.fillna(x.mean())))
# qatar['midfield_score'] = round(qatar["midfield_score"].transform(lambda x: x.fillna(x.mean())))
# qatar['defense_score'] = round(qatar["defense_score"].transform(lambda x: x.fillna(x.mean())))
# # qatar.head(5)
#
#
# # Exporting the "Last Team Scores" dataset.
#
# # In[ ]:
#

# qatar.to_csv("/content/drive/MyDrive/data/last_team_scores.csv", index = False)

if __name__ == "__main__":
    main()