-
Notifications
You must be signed in to change notification settings - Fork 8
/
Players_names_fix.py
159 lines (65 loc) · 1.79 KB
/
Players_names_fix.py
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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
#load matches dataset
import pandas as pd
matches_dataset_final = pd.read_csv('final_kaggle_dataset.csv')
# In[2]:
#load players data
players_dataset = pd.read_csv('players_data.csv')
# In[3]:
#get unique player id from matches
players_from_matches = matches_dataset_final['player_id'].unique()
# In[4]:
len(players_from_matches)
# In[5]:
len(players_dataset)
# In[6]:
players_list = players_dataset['player_id'].tolist()
# In[7]:
players_list
# In[8]:
players_from_matches
# In[9]:
diff = list(set(players_list)-set(players_from_matches))
# In[10]:
diff
# In[16]:
len(diff)
# In[27]:
#remove players that are too old (born before 1960)
for i in range(0,len(players_dataset)-1):
yob = players_dataset.iloc[i]['dob']
yob = str(yob)
yob = yob[:4]
yob = int(yob)
if yob <= 1960 :
players_dataset = players_dataset.drop(players_dataset.index[i])
# In[22]:
type(players_dataset.iloc[7]['dob'])
# In[28]:
players_dataset
# In[30]:
#save data
players_dataset.to_csv('players_data.csv')
# In[13]:
plyrs = pd.DataFrame(data=players_from_matches,columns=['player_id'])
plyrs
# In[29]:
#find players we need in players_data
needed_players = pd.DataFrame()
for i in range(len(plyrs)):
row = players_dataset.loc[plyrs.iloc[i]['player_id'] == players_dataset['player_id'] ]
needed_players = needed_players.append(row,ignore_index=True)
# In[19]:
players_dataset.loc[plyrs.iloc[0]['player_id'] == players_dataset['player_id'] ]
# In[30]:
needed_players
# In[35]:
#merge with remaining
merged_players_data = pd.merge(needed_players,plyrs,on='player_id',how='outer')
# In[36]:
merged_players_data
# In[37]:
merged_players_data.to_csv('players_data_1.csv')
# In[ ]: