Statement of Completion#bd4f06cb
Intro to Pandas for Data Analysis
easy
Practicing Filtering and Selection with FIFA data
Resolution
Activities
In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
In [2]:
df = pd.read_csv('players_22.csv',dtype={25: str, 108: str})
Let's Analyze our DataFrame¶
we will see the first few rows of the dataframe using df.head()
, if we want to check the last few rows then we will use df.tail()
,
After that, we will check the names of columns using df.columns
, check the datatype, and values in each column using df.info()
.
Lastly, to find the statistical features we use df.describe()
.
In [3]:
df.head()
Out[3]:
sofifa_id | player_url | short_name | long_name | player_positions | overall | potential | value_eur | wage_eur | age | ... | lcb | cb | rcb | rb | gk | player_face_url | club_logo_url | club_flag_url | nation_logo_url | nation_flag_url | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 158023 | https://sofifa.com/player/158023/lionel-messi/... | L. Messi | Lionel Andrés Messi Cuccittini | RW, ST, CF | 93 | 93 | 78000000.0 | 320000.0 | 34 | ... | 50+3 | 50+3 | 50+3 | 61+3 | 19+3 | https://cdn.sofifa.net/players/158/023/22_120.png | https://cdn.sofifa.net/teams/73/60.png | https://cdn.sofifa.net/flags/fr.png | https://cdn.sofifa.net/teams/1369/60.png | https://cdn.sofifa.net/flags/ar.png |
1 | 188545 | https://sofifa.com/player/188545/robert-lewand... | R. Lewandowski | Robert Lewandowski | ST | 92 | 92 | 119500000.0 | 270000.0 | 32 | ... | 60+3 | 60+3 | 60+3 | 61+3 | 19+3 | https://cdn.sofifa.net/players/188/545/22_120.png | https://cdn.sofifa.net/teams/21/60.png | https://cdn.sofifa.net/flags/de.png | https://cdn.sofifa.net/teams/1353/60.png | https://cdn.sofifa.net/flags/pl.png |
2 | 20801 | https://sofifa.com/player/20801/c-ronaldo-dos-... | Cristiano Ronaldo | Cristiano Ronaldo dos Santos Aveiro | ST, LW | 91 | 91 | 45000000.0 | 270000.0 | 36 | ... | 53+3 | 53+3 | 53+3 | 60+3 | 20+3 | https://cdn.sofifa.net/players/020/801/22_120.png | https://cdn.sofifa.net/teams/11/60.png | https://cdn.sofifa.net/flags/gb-eng.png | https://cdn.sofifa.net/teams/1354/60.png | https://cdn.sofifa.net/flags/pt.png |
3 | 190871 | https://sofifa.com/player/190871/neymar-da-sil... | Neymar Jr | Neymar da Silva Santos Júnior | LW, CAM | 91 | 91 | 129000000.0 | 270000.0 | 29 | ... | 50+3 | 50+3 | 50+3 | 62+3 | 20+3 | https://cdn.sofifa.net/players/190/871/22_120.png | https://cdn.sofifa.net/teams/73/60.png | https://cdn.sofifa.net/flags/fr.png | NaN | https://cdn.sofifa.net/flags/br.png |
4 | 192985 | https://sofifa.com/player/192985/kevin-de-bruy... | K. De Bruyne | Kevin De Bruyne | CM, CAM | 91 | 91 | 125500000.0 | 350000.0 | 30 | ... | 69+3 | 69+3 | 69+3 | 75+3 | 21+3 | https://cdn.sofifa.net/players/192/985/22_120.png | https://cdn.sofifa.net/teams/10/60.png | https://cdn.sofifa.net/flags/gb-eng.png | https://cdn.sofifa.net/teams/1325/60.png | https://cdn.sofifa.net/flags/be.png |
5 rows × 110 columns
In [4]:
df.columns
Out[4]:
Index(['sofifa_id', 'player_url', 'short_name', 'long_name', 'player_positions', 'overall', 'potential', 'value_eur', 'wage_eur', 'age', ... 'lcb', 'cb', 'rcb', 'rb', 'gk', 'player_face_url', 'club_logo_url', 'club_flag_url', 'nation_logo_url', 'nation_flag_url'], dtype='object', length=110)
In [5]:
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 19239 entries, 0 to 19238 Columns: 110 entries, sofifa_id to nation_flag_url dtypes: float64(16), int64(44), object(50) memory usage: 16.1+ MB
In [6]:
df.describe()
Out[6]:
sofifa_id | overall | potential | value_eur | wage_eur | age | height_cm | weight_kg | club_team_id | league_level | ... | mentality_composure | defending_marking_awareness | defending_standing_tackle | defending_sliding_tackle | goalkeeping_diving | goalkeeping_handling | goalkeeping_kicking | goalkeeping_positioning | goalkeeping_reflexes | goalkeeping_speed | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count | 19239.000000 | 19239.000000 | 19239.000000 | 1.916500e+04 | 19178.000000 | 19239.000000 | 19239.000000 | 19239.000000 | 19178.000000 | 19178.000000 | ... | 19239.000000 | 19239.000000 | 19239.000000 | 19239.000000 | 19239.000000 | 19239.000000 | 19239.000000 | 19239.000000 | 19239.000000 | 2132.000000 |
mean | 231468.086959 | 65.772182 | 71.079370 | 2.850452e+06 | 9017.989363 | 25.210822 | 181.299704 | 74.943032 | 50580.498123 | 1.354364 | ... | 57.929830 | 46.601746 | 48.045584 | 45.906700 | 16.406102 | 16.192474 | 16.055356 | 16.229274 | 16.491814 | 36.439962 |
std | 27039.717497 | 6.880232 | 6.086213 | 7.613700e+06 | 19470.176724 | 4.748235 | 6.863179 | 7.069434 | 54401.868535 | 0.747865 | ... | 12.159326 | 20.200807 | 21.232718 | 20.755683 | 17.574028 | 16.839528 | 16.564554 | 17.059779 | 17.884833 | 10.751563 |
min | 41.000000 | 47.000000 | 49.000000 | 9.000000e+03 | 500.000000 | 16.000000 | 155.000000 | 49.000000 | 1.000000 | 1.000000 | ... | 12.000000 | 4.000000 | 5.000000 | 5.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 15.000000 |
25% | 214413.500000 | 61.000000 | 67.000000 | 4.750000e+05 | 1000.000000 | 21.000000 | 176.000000 | 70.000000 | 479.000000 | 1.000000 | ... | 50.000000 | 29.000000 | 28.000000 | 25.000000 | 8.000000 | 8.000000 | 8.000000 | 8.000000 | 8.000000 | 27.000000 |
50% | 236543.000000 | 66.000000 | 71.000000 | 9.750000e+05 | 3000.000000 | 25.000000 | 181.000000 | 75.000000 | 1938.000000 | 1.000000 | ... | 59.000000 | 52.000000 | 56.000000 | 53.000000 | 11.000000 | 11.000000 | 11.000000 | 11.000000 | 11.000000 | 36.000000 |
75% | 253532.500000 | 70.000000 | 75.000000 | 2.000000e+06 | 8000.000000 | 29.000000 | 186.000000 | 80.000000 | 111139.000000 | 1.000000 | ... | 66.000000 | 63.000000 | 65.000000 | 63.000000 | 14.000000 | 14.000000 | 14.000000 | 14.000000 | 14.000000 | 45.000000 |
max | 264640.000000 | 93.000000 | 95.000000 | 1.940000e+08 | 350000.000000 | 54.000000 | 206.000000 | 110.000000 | 115820.000000 | 5.000000 | ... | 96.000000 | 93.000000 | 93.000000 | 92.000000 | 91.000000 | 92.000000 | 93.000000 | 92.000000 | 90.000000 | 65.000000 |
8 rows × 60 columns
Some visualizations to better understand the dataset¶
In [22]:
df['age'].plot(kind='hist', figsize=(10, 8))
Out[22]:
<AxesSubplot:ylabel='Frequency'>
In [23]:
df['overall'].plot(kind='box', vert=False, figsize=(10, 5))
Out[23]:
<AxesSubplot:>
In [24]:
sns.distplot(df['age']);
/home/qalmaqihir/anaconda3/lib/python3.9/site-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). warnings.warn(msg, FutureWarning)
In [25]:
df['international_reputation'].value_counts().plot(kind='pie', autopct='%1.1f%%', cmap='Set3', figsize=(10, 8))
Out[25]:
<AxesSubplot:ylabel='international_reputation'>
In [26]:
df['nationality_name'].value_counts().head(10).plot(kind='pie', autopct='%1.1f%%', cmap='Set3', figsize=(10, 8))
Out[26]:
<AxesSubplot:ylabel='nationality_name'>
In [27]:
df['work_rate'].value_counts().plot(kind='pie', autopct='%1.1f%%', cmap='Set3', figsize=(10, 8))
Out[27]:
<AxesSubplot:ylabel='work_rate'>
Filtering¶
Below we will do some basic as well as advance filtering on our FIFA Players 22 dataset.
1. Select all the rows and the first 5 columns from the dataframe and store the result in the variable df_first_five_cols
In [13]:
df_first_five_cols = df.iloc[:,:5]
df_first_five_cols
Out[13]:
sofifa_id | player_url | short_name | long_name | player_positions | |
---|---|---|---|---|---|
0 | 158023 | https://sofifa.com/player/158023/lionel-messi/... | L. Messi | Lionel Andrés Messi Cuccittini | RW, ST, CF |
1 | 188545 | https://sofifa.com/player/188545/robert-lewand... | R. Lewandowski | Robert Lewandowski | ST |
2 | 20801 | https://sofifa.com/player/20801/c-ronaldo-dos-... | Cristiano Ronaldo | Cristiano Ronaldo dos Santos Aveiro | ST, LW |
3 | 190871 | https://sofifa.com/player/190871/neymar-da-sil... | Neymar Jr | Neymar da Silva Santos Júnior | LW, CAM |
4 | 192985 | https://sofifa.com/player/192985/kevin-de-bruy... | K. De Bruyne | Kevin De Bruyne | CM, CAM |
... | ... | ... | ... | ... | ... |
19234 | 261962 | https://sofifa.com/player/261962/defu-song/220002 | Song Defu | 宋德福 | CDM |
19235 | 262040 | https://sofifa.com/player/262040/caoimhin-port... | C. Porter | Caoimhin Porter | CM |
19236 | 262760 | https://sofifa.com/player/262760/nathan-logue/... | N. Logue | Nathan Logue-Cunningham | CM |
19237 | 262820 | https://sofifa.com/player/262820/luke-rudden/2... | L. Rudden | Luke Rudden | ST |
19238 | 264540 | https://sofifa.com/player/264540/emanuel-lalch... | E. Lalchhanchhuaha | Emanuel Lalchhanchhuaha | CAM |
19239 rows × 5 columns
In [ ]:
2. Select Specific Columns in a Custom Order
In [19]:
df_order_cols = df.iloc[:,[3,6,4,1]]
df_order_cols
Out[19]:
long_name | potential | player_positions | player_url | |
---|---|---|---|---|
0 | Lionel Andrés Messi Cuccittini | 93 | RW, ST, CF | https://sofifa.com/player/158023/lionel-messi/... |
1 | Robert Lewandowski | 92 | ST | https://sofifa.com/player/188545/robert-lewand... |
2 | Cristiano Ronaldo dos Santos Aveiro | 91 | ST, LW | https://sofifa.com/player/20801/c-ronaldo-dos-... |
3 | Neymar da Silva Santos Júnior | 91 | LW, CAM | https://sofifa.com/player/190871/neymar-da-sil... |
4 | Kevin De Bruyne | 91 | CM, CAM | https://sofifa.com/player/192985/kevin-de-bruy... |
... | ... | ... | ... | ... |
19234 | 宋德福 | 52 | CDM | https://sofifa.com/player/261962/defu-song/220002 |
19235 | Caoimhin Porter | 59 | CM | https://sofifa.com/player/262040/caoimhin-port... |
19236 | Nathan Logue-Cunningham | 55 | CM | https://sofifa.com/player/262760/nathan-logue/... |
19237 | Luke Rudden | 60 | ST | https://sofifa.com/player/262820/luke-rudden/2... |
19238 | Emanuel Lalchhanchhuaha | 60 | CAM | https://sofifa.com/player/264540/emanuel-lalch... |
19239 rows × 4 columns
In [ ]:
3. Filter out 50 rows from the Colum number 3,6,4,1 into the variable fifty_rows
In [23]:
fifty_rows = df.iloc[:50,[3,6,4,1]]
fifty_rows
Out[23]:
long_name | potential | player_positions | player_url | |
---|---|---|---|---|
0 | Lionel Andrés Messi Cuccittini | 93 | RW, ST, CF | https://sofifa.com/player/158023/lionel-messi/... |
1 | Robert Lewandowski | 92 | ST | https://sofifa.com/player/188545/robert-lewand... |
2 | Cristiano Ronaldo dos Santos Aveiro | 91 | ST, LW | https://sofifa.com/player/20801/c-ronaldo-dos-... |
3 | Neymar da Silva Santos Júnior | 91 | LW, CAM | https://sofifa.com/player/190871/neymar-da-sil... |
4 | Kevin De Bruyne | 91 | CM, CAM | https://sofifa.com/player/192985/kevin-de-bruy... |
5 | Jan Oblak | 93 | GK | https://sofifa.com/player/200389/jan-oblak/220002 |
6 | Kylian Mbappé Lottin | 95 | ST, LW | https://sofifa.com/player/231747/kylian-mbappe... |
7 | Manuel Peter Neuer | 90 | GK | https://sofifa.com/player/167495/manuel-neuer/... |
8 | Marc-André ter Stegen | 92 | GK | https://sofifa.com/player/192448/marc-andre-te... |
9 | Harry Kane | 90 | ST | https://sofifa.com/player/202126/harry-kane/22... |
10 | N'Golo Kanté | 90 | CDM, CM | https://sofifa.com/player/215914/ngolo-kante/2... |
11 | Karim Benzema | 89 | CF, ST | https://sofifa.com/player/165153/karim-benzema... |
12 | Thibaut Courtois | 91 | GK | https://sofifa.com/player/192119/thibaut-court... |
13 | 손흥민 孙兴慜 | 89 | LM, CF, LW | https://sofifa.com/player/200104/heung-min-son... |
14 | Carlos Henrique Venancio Casimiro | 89 | CDM | https://sofifa.com/player/200145/carlos-henriq... |
15 | Virgil van Dijk | 89 | CB | https://sofifa.com/player/203376/virgil-van-di... |
16 | Sadio Mané | 89 | LW | https://sofifa.com/player/208722/sadio-mane/22... |
17 | Mohamed Salah Ghaly | 89 | RW | https://sofifa.com/player/209331/mohamed-salah... |
18 | Ederson Santana de Moraes | 91 | GK | https://sofifa.com/player/210257/ederson-santa... |
19 | Joshua Walter Kimmich | 90 | CDM, RB | https://sofifa.com/player/212622/joshua-kimmic... |
20 | Alisson Ramsés Becker | 90 | GK | https://sofifa.com/player/212831/alisson-ramse... |
21 | Gianluigi Donnarumma | 93 | GK | https://sofifa.com/player/230621/gianluigi-don... |
22 | Sergio Ramos García | 88 | CB | https://sofifa.com/player/155862/sergio-ramos-... |
23 | Luis Alberto Suárez Díaz | 88 | ST | https://sofifa.com/player/176580/luis-suarez/2... |
24 | Toni Kroos | 88 | CM | https://sofifa.com/player/182521/toni-kroos/22... |
25 | Romelu Lukaku Menama | 88 | ST | https://sofifa.com/player/192505/romelu-lukaku... |
26 | Keylor Navas Gamboa | 88 | GK | https://sofifa.com/player/193041/keylor-navas/... |
27 | Raheem Sterling | 89 | LW, RW | https://sofifa.com/player/202652/raheem-sterli... |
28 | Bruno Miguel Borges Fernandes | 89 | CAM | https://sofifa.com/player/212198/bruno-miguel-... |
29 | Erling Braut Haaland | 93 | ST | https://sofifa.com/player/239085/erling-haalan... |
30 | Sergio Leonel Agüero del Castillo | 87 | ST | https://sofifa.com/player/153079/sergio-aguero... |
31 | Hugo Lloris | 87 | GK | https://sofifa.com/player/167948/hugo-lloris/2... |
32 | Luka Modrić | 87 | CM | https://sofifa.com/player/177003/luka-modric/2... |
33 | Ángel Fabián Di María Hernández | 87 | RW, LW | https://sofifa.com/player/183898/angel-di-mari... |
34 | Wojciech Tomasz Szczęsny | 87 | GK | https://sofifa.com/player/186153/wojciech-szcz... |
35 | Thomas Müller | 87 | CAM, RM, RW | https://sofifa.com/player/189596/thomas-muller... |
36 | Ciro Immobile | 87 | ST | https://sofifa.com/player/192387/ciro-immobile... |
37 | Paul Pogba | 87 | CM, LM | https://sofifa.com/player/195864/paul-pogba/22... |
38 | Marco Verratti | 87 | CM, CAM | https://sofifa.com/player/199556/marco-verratt... |
39 | Marcos Aoás Corrêa | 90 | CB, CDM | https://sofifa.com/player/207865/marcos-aoas-c... |
40 | Leon Christoph Goretzka | 88 | CM, CDM | https://sofifa.com/player/209658/leon-goretzka... |
41 | Paulo Bruno Exequiel Dybala | 88 | CF, CAM | https://sofifa.com/player/211110/paulo-dybala/... |
42 | Andrew Robertson | 88 | LB | https://sofifa.com/player/216267/andrew-robert... |
43 | Frenkie de Jong | 92 | CM, CDM, CB | https://sofifa.com/player/228702/frenkie-de-jo... |
44 | Trent Alexander-Arnold | 92 | RB | https://sofifa.com/player/231281/trent-alexand... |
45 | Jadon Sancho | 91 | RM, CF, LM | https://sofifa.com/player/233049/jadon-sancho/... |
46 | Rúben dos Santos Gato Alves Dias | 91 | CB | https://sofifa.com/player/239818/ruben-santos-... |
47 | Giorgio Chiellini | 86 | CB | https://sofifa.com/player/138956/giorgio-chiel... |
48 | Samir Handanovič | 86 | GK | https://sofifa.com/player/162835/samir-handano... |
49 | Mats Hummels | 86 | CB | https://sofifa.com/player/178603/mats-hummels/... |
In [ ]:
4. Select the all rows and the Columns ['short_name','age','player_positions', 'overall', 'value_eur']
from the dataframe and store your selection in the variable named_cols
In [27]:
named_cols= df.loc[:,['short_name','age','player_positions','overall','value_eur']]
named_cols
Out[27]:
short_name | age | player_positions | overall | value_eur | |
---|---|---|---|---|---|
0 | L. Messi | 34 | RW, ST, CF | 93 | 78000000.0 |
1 | R. Lewandowski | 32 | ST | 92 | 119500000.0 |
2 | Cristiano Ronaldo | 36 | ST, LW | 91 | 45000000.0 |
3 | Neymar Jr | 29 | LW, CAM | 91 | 129000000.0 |
4 | K. De Bruyne | 30 | CM, CAM | 91 | 125500000.0 |
... | ... | ... | ... | ... | ... |
19234 | Song Defu | 22 | CDM | 47 | 70000.0 |
19235 | C. Porter | 19 | CM | 47 | 110000.0 |
19236 | N. Logue | 21 | CM | 47 | 100000.0 |
19237 | L. Rudden | 19 | ST | 47 | 110000.0 |
19238 | E. Lalchhanchhuaha | 19 | CAM | 47 | 110000.0 |
19239 rows × 5 columns
In [ ]:
5. Filter out the first 14 rows and the Columns ['short_name','age','player_positions', 'overall', 'value_eur']
from the dataframe and store the result in the variable named_cols_rows
In [33]:
named_cols_rows = df.loc[:13,['short_name','age','player_positions','overall','value_eur']]
named_cols_rows
Out[33]:
short_name | age | player_positions | overall | value_eur | |
---|---|---|---|---|---|
0 | L. Messi | 34 | RW, ST, CF | 93 | 78000000.0 |
1 | R. Lewandowski | 32 | ST | 92 | 119500000.0 |
2 | Cristiano Ronaldo | 36 | ST, LW | 91 | 45000000.0 |
3 | Neymar Jr | 29 | LW, CAM | 91 | 129000000.0 |
4 | K. De Bruyne | 30 | CM, CAM | 91 | 125500000.0 |
5 | J. Oblak | 28 | GK | 91 | 112000000.0 |
6 | K. Mbappé | 22 | ST, LW | 91 | 194000000.0 |
7 | M. Neuer | 35 | GK | 90 | 13500000.0 |
8 | M. ter Stegen | 29 | GK | 90 | 99000000.0 |
9 | H. Kane | 27 | ST | 90 | 129500000.0 |
10 | N. Kanté | 30 | CDM, CM | 90 | 100000000.0 |
11 | K. Benzema | 33 | CF, ST | 89 | 66000000.0 |
12 | T. Courtois | 29 | GK | 89 | 85500000.0 |
13 | H. Son | 28 | LM, CF, LW | 89 | 104000000.0 |
In [ ]:
6. Find out how many players of overall
rating greater than 90 exists in the dataset?
In [36]:
df[df['overall']>90]
Out[36]:
sofifa_id | player_url | short_name | long_name | player_positions | overall | potential | value_eur | wage_eur | age | ... | lcb | cb | rcb | rb | gk | player_face_url | club_logo_url | club_flag_url | nation_logo_url | nation_flag_url | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 158023 | https://sofifa.com/player/158023/lionel-messi/... | L. Messi | Lionel Andrés Messi Cuccittini | RW, ST, CF | 93 | 93 | 78000000.0 | 320000.0 | 34 | ... | 50+3 | 50+3 | 50+3 | 61+3 | 19+3 | https://cdn.sofifa.net/players/158/023/22_120.png | https://cdn.sofifa.net/teams/73/60.png | https://cdn.sofifa.net/flags/fr.png | https://cdn.sofifa.net/teams/1369/60.png | https://cdn.sofifa.net/flags/ar.png |
1 | 188545 | https://sofifa.com/player/188545/robert-lewand... | R. Lewandowski | Robert Lewandowski | ST | 92 | 92 | 119500000.0 | 270000.0 | 32 | ... | 60+3 | 60+3 | 60+3 | 61+3 | 19+3 | https://cdn.sofifa.net/players/188/545/22_120.png | https://cdn.sofifa.net/teams/21/60.png | https://cdn.sofifa.net/flags/de.png | https://cdn.sofifa.net/teams/1353/60.png | https://cdn.sofifa.net/flags/pl.png |
2 | 20801 | https://sofifa.com/player/20801/c-ronaldo-dos-... | Cristiano Ronaldo | Cristiano Ronaldo dos Santos Aveiro | ST, LW | 91 | 91 | 45000000.0 | 270000.0 | 36 | ... | 53+3 | 53+3 | 53+3 | 60+3 | 20+3 | https://cdn.sofifa.net/players/020/801/22_120.png | https://cdn.sofifa.net/teams/11/60.png | https://cdn.sofifa.net/flags/gb-eng.png | https://cdn.sofifa.net/teams/1354/60.png | https://cdn.sofifa.net/flags/pt.png |
3 | 190871 | https://sofifa.com/player/190871/neymar-da-sil... | Neymar Jr | Neymar da Silva Santos Júnior | LW, CAM | 91 | 91 | 129000000.0 | 270000.0 | 29 | ... | 50+3 | 50+3 | 50+3 | 62+3 | 20+3 | https://cdn.sofifa.net/players/190/871/22_120.png | https://cdn.sofifa.net/teams/73/60.png | https://cdn.sofifa.net/flags/fr.png | NaN | https://cdn.sofifa.net/flags/br.png |
4 | 192985 | https://sofifa.com/player/192985/kevin-de-bruy... | K. De Bruyne | Kevin De Bruyne | CM, CAM | 91 | 91 | 125500000.0 | 350000.0 | 30 | ... | 69+3 | 69+3 | 69+3 | 75+3 | 21+3 | https://cdn.sofifa.net/players/192/985/22_120.png | https://cdn.sofifa.net/teams/10/60.png | https://cdn.sofifa.net/flags/gb-eng.png | https://cdn.sofifa.net/teams/1325/60.png | https://cdn.sofifa.net/flags/be.png |
5 | 200389 | https://sofifa.com/player/200389/jan-oblak/220002 | J. Oblak | Jan Oblak | GK | 91 | 93 | 112000000.0 | 130000.0 | 28 | ... | 33+3 | 33+3 | 33+3 | 32+3 | 89+3 | https://cdn.sofifa.net/players/200/389/22_120.png | https://cdn.sofifa.net/teams/240/60.png | https://cdn.sofifa.net/flags/es.png | NaN | https://cdn.sofifa.net/flags/si.png |
6 | 231747 | https://sofifa.com/player/231747/kylian-mbappe... | K. Mbappé | Kylian Mbappé Lottin | ST, LW | 91 | 95 | 194000000.0 | 230000.0 | 22 | ... | 54+3 | 54+3 | 54+3 | 63+3 | 18+3 | https://cdn.sofifa.net/players/231/747/22_120.png | https://cdn.sofifa.net/teams/73/60.png | https://cdn.sofifa.net/flags/fr.png | https://cdn.sofifa.net/teams/1335/60.png | https://cdn.sofifa.net/flags/fr.png |
7 rows × 110 columns
7. Find out how many players of value_eur
of less than or equal to 20000 in the dataset?
In [38]:
df[df['value_eur']<=20000]
Out[38]:
sofifa_id | player_url | short_name | long_name | player_positions | overall | potential | value_eur | wage_eur | age | ... | lcb | cb | rcb | rb | gk | player_face_url | club_logo_url | club_flag_url | nation_logo_url | nation_flag_url | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
16996 | 140300 | https://sofifa.com/player/140300/peter-cherrie... | P. Cherrie | Peter Cherrie | GK | 57 | 57 | 20000.0 | 500.0 | 37 | ... | 25+2 | 25+2 | 25+2 | 20+2 | 56+1 | https://cdn.sofifa.net/players/140/300/22_120.png | https://cdn.sofifa.net/teams/837/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/gb-sct.png |
17000 | 186838 | https://sofifa.com/player/186838/gerard-dohert... | G. Doherty | Gerard Doherty | GK | 57 | 57 | 20000.0 | 500.0 | 39 | ... | 26+2 | 26+2 | 26+2 | 23+2 | 56+1 | https://cdn.sofifa.net/players/186/838/22_120.png | https://cdn.sofifa.net/teams/111131/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/gb-nir.png |
17034 | 232473 | https://sofifa.com/player/232473/hitoshi-shiot... | H. Shiota | 土田 仁史 | GK | 57 | 57 | 20000.0 | 900.0 | 40 | ... | 22+2 | 22+2 | 22+2 | 19+2 | 56+1 | https://cdn.sofifa.net/players/232/473/22_120.png | https://cdn.sofifa.net/teams/111575/60.png | https://cdn.sofifa.net/flags/jp.png | NaN | https://cdn.sofifa.net/flags/jp.png |
17435 | 102881 | https://sofifa.com/player/102881/kyriakos-stam... | K. Stamatopoulos | Kyriakos Stamatopoulos | GK | 56 | 56 | 15000.0 | 600.0 | 41 | ... | 25+2 | 25+2 | 25+2 | 24+2 | 55+1 | https://cdn.sofifa.net/players/102/881/22_120.png | https://cdn.sofifa.net/teams/433/60.png | https://cdn.sofifa.net/flags/se.png | NaN | https://cdn.sofifa.net/flags/ca.png |
17436 | 166713 | https://sofifa.com/player/166713/barry-murphy/... | B. Murphy | Barry Murphy | GK | 56 | 56 | 15000.0 | 500.0 | 36 | ... | 26+2 | 26+2 | 26+2 | 24+2 | 55+1 | https://cdn.sofifa.net/players/166/713/22_120.png | https://cdn.sofifa.net/teams/423/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/ie.png |
17438 | 183031 | https://sofifa.com/player/183031/feng-han/220002 | Han Feng | 韩锋 | GK | 56 | 56 | 15000.0 | 750.0 | 37 | ... | 30+2 | 30+2 | 30+2 | 28+2 | 55+1 | https://cdn.sofifa.net/players/183/031/22_120.png | https://cdn.sofifa.net/teams/112985/60.png | https://cdn.sofifa.net/flags/cn.png | NaN | https://cdn.sofifa.net/flags/cn.png |
17797 | 138431 | https://sofifa.com/player/138431/richard-brush... | R. Brush | Richard Brush | GK | 55 | 55 | 15000.0 | 500.0 | 36 | ... | 24+2 | 24+2 | 24+2 | 23+2 | 54+1 | https://cdn.sofifa.net/players/138/431/22_120.png | https://cdn.sofifa.net/teams/563/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/gb-eng.png |
18658 | 149697 | https://sofifa.com/player/149697/mark-mcchryst... | M. McChrystal | Mark Thomas McChrystal | CB | 52 | 52 | 15000.0 | 500.0 | 37 | ... | 52 | 52 | 52 | 44+2 | 16+2 | https://cdn.sofifa.net/players/149/697/22_120.png | https://cdn.sofifa.net/teams/445/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/gb-nir.png |
18671 | 245558 | https://sofifa.com/player/245558/gary-maley/22... | G. Maley | Gary Maley | GK | 52 | 52 | 9000.0 | 600.0 | 38 | ... | 19+2 | 19+2 | 19+2 | 16+2 | 51+1 | https://cdn.sofifa.net/players/245/558/22_120.png | https://cdn.sofifa.net/teams/621/60.png | https://cdn.sofifa.net/flags/gb-sct.png | NaN | https://cdn.sofifa.net/flags/gb-sct.png |
19100 | 157190 | https://sofifa.com/player/157190/john-russell/... | J. Russell | John Russell | CM, CDM | 49 | 49 | 15000.0 | 500.0 | 36 | ... | 50-1 | 50-1 | 50-1 | 46+2 | 14+2 | https://cdn.sofifa.net/players/157/190/22_120.png | https://cdn.sofifa.net/teams/563/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/ie.png |
10 rows × 110 columns
8. Select the long_name
and age
of the players having the club_name='Manchester City'
and store your selection in the variable name long_name_age
In [40]:
long_name_age = df[['long_name','age']][df['club_name']=='Manchester City']
long_name_age
Out[40]:
long_name | age | |
---|---|---|
4 | Kevin De Bruyne | 30 |
18 | Ederson Santana de Moraes | 27 |
27 | Raheem Sterling | 26 |
46 | Rúben dos Santos Gato Alves Dias | 24 |
58 | Riyad Mahrez | 30 |
62 | João Pedro Cavaco Cancelo | 27 |
63 | Aymeric Laporte | 27 |
65 | Bernardo Mota Veiga de Carvalho e Silva | 26 |
67 | Rodrigo Hernández Cascante | 25 |
78 | İlkay Gündoğan | 30 |
80 | Kyle Walker | 31 |
118 | Jack Grealish | 25 |
139 | Philip Foden | 21 |
140 | Fernando Luiz Rosa | 36 |
166 | John Stones | 27 |
191 | Gabriel Fernando de Jesus | 24 |
280 | Ferran Torres García | 21 |
477 | Oleksandr Zinchenko | 24 |
569 | Benjamin Mendy | 26 |
745 | Nathan Aké | 26 |
1075 | Zack Thomas Steffen | 26 |
7487 | Scott Carson | 35 |
9771 | Kayky da Silva Chagas | 18 |
11543 | Luke Bolton | 21 |
12055 | Cole Palmer | 19 |
12095 | Liam Delap | 18 |
12113 | Jayden Jezairo Braaf | 18 |
14275 | Luke Mbete | 17 |
14349 | Romeo Lavia | 17 |
14364 | Samuel Edozie | 18 |
15157 | James McAtee | 18 |
17084 | Iker Pozo La Rosa | 20 |
In [ ]:
9. Filter out the players of Liverpool
club and who are from Brazil
and store them in the variable liverpool_brazil
Note: club_name
& nationality_name
are the column names
In [43]:
liverpool_brazil = df[(df['club_name']=='Liverpool') & (df['nationality_name']=='Brazil')]
In [ ]:
10. How many players are there who have either mentality_aggression > 91
or power_stamina < 80
Note: Using query method will be easy
In [49]:
df[(df['mentality_aggression']>91)|(df['power_stamina']<80)]
Out[49]:
sofifa_id | player_url | short_name | long_name | player_positions | overall | potential | value_eur | wage_eur | age | ... | lcb | cb | rcb | rb | gk | player_face_url | club_logo_url | club_flag_url | nation_logo_url | nation_flag_url | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 158023 | https://sofifa.com/player/158023/lionel-messi/... | L. Messi | Lionel Andrés Messi Cuccittini | RW, ST, CF | 93 | 93 | 78000000.0 | 320000.0 | 34 | ... | 50+3 | 50+3 | 50+3 | 61+3 | 19+3 | https://cdn.sofifa.net/players/158/023/22_120.png | https://cdn.sofifa.net/teams/73/60.png | https://cdn.sofifa.net/flags/fr.png | https://cdn.sofifa.net/teams/1369/60.png | https://cdn.sofifa.net/flags/ar.png |
1 | 188545 | https://sofifa.com/player/188545/robert-lewand... | R. Lewandowski | Robert Lewandowski | ST | 92 | 92 | 119500000.0 | 270000.0 | 32 | ... | 60+3 | 60+3 | 60+3 | 61+3 | 19+3 | https://cdn.sofifa.net/players/188/545/22_120.png | https://cdn.sofifa.net/teams/21/60.png | https://cdn.sofifa.net/flags/de.png | https://cdn.sofifa.net/teams/1353/60.png | https://cdn.sofifa.net/flags/pl.png |
2 | 20801 | https://sofifa.com/player/20801/c-ronaldo-dos-... | Cristiano Ronaldo | Cristiano Ronaldo dos Santos Aveiro | ST, LW | 91 | 91 | 45000000.0 | 270000.0 | 36 | ... | 53+3 | 53+3 | 53+3 | 60+3 | 20+3 | https://cdn.sofifa.net/players/020/801/22_120.png | https://cdn.sofifa.net/teams/11/60.png | https://cdn.sofifa.net/flags/gb-eng.png | https://cdn.sofifa.net/teams/1354/60.png | https://cdn.sofifa.net/flags/pt.png |
5 | 200389 | https://sofifa.com/player/200389/jan-oblak/220002 | J. Oblak | Jan Oblak | GK | 91 | 93 | 112000000.0 | 130000.0 | 28 | ... | 33+3 | 33+3 | 33+3 | 32+3 | 89+3 | https://cdn.sofifa.net/players/200/389/22_120.png | https://cdn.sofifa.net/teams/240/60.png | https://cdn.sofifa.net/flags/es.png | NaN | https://cdn.sofifa.net/flags/si.png |
7 | 167495 | https://sofifa.com/player/167495/manuel-neuer/... | M. Neuer | Manuel Peter Neuer | GK | 90 | 90 | 13500000.0 | 86000.0 | 35 | ... | 34+3 | 34+3 | 34+3 | 35+3 | 88+2 | https://cdn.sofifa.net/players/167/495/22_120.png | https://cdn.sofifa.net/teams/21/60.png | https://cdn.sofifa.net/flags/de.png | https://cdn.sofifa.net/teams/1337/60.png | https://cdn.sofifa.net/flags/de.png |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
19234 | 261962 | https://sofifa.com/player/261962/defu-song/220002 | Song Defu | 宋德福 | CDM | 47 | 52 | 70000.0 | 1000.0 | 22 | ... | 46+2 | 46+2 | 46+2 | 48+2 | 15+2 | https://cdn.sofifa.net/players/261/962/22_120.png | https://cdn.sofifa.net/teams/112541/60.png | https://cdn.sofifa.net/flags/cn.png | NaN | https://cdn.sofifa.net/flags/cn.png |
19235 | 262040 | https://sofifa.com/player/262040/caoimhin-port... | C. Porter | Caoimhin Porter | CM | 47 | 59 | 110000.0 | 500.0 | 19 | ... | 44+2 | 44+2 | 44+2 | 48+2 | 14+2 | https://cdn.sofifa.net/players/262/040/22_120.png | https://cdn.sofifa.net/teams/445/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/ie.png |
19236 | 262760 | https://sofifa.com/player/262760/nathan-logue/... | N. Logue | Nathan Logue-Cunningham | CM | 47 | 55 | 100000.0 | 500.0 | 21 | ... | 45+2 | 45+2 | 45+2 | 47+2 | 12+2 | https://cdn.sofifa.net/players/262/760/22_120.png | https://cdn.sofifa.net/teams/111131/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/ie.png |
19237 | 262820 | https://sofifa.com/player/262820/luke-rudden/2... | L. Rudden | Luke Rudden | ST | 47 | 60 | 110000.0 | 500.0 | 19 | ... | 26+2 | 26+2 | 26+2 | 32+2 | 15+2 | https://cdn.sofifa.net/players/262/820/22_120.png | https://cdn.sofifa.net/teams/111131/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/ie.png |
19238 | 264540 | https://sofifa.com/player/264540/emanuel-lalch... | E. Lalchhanchhuaha | Emanuel Lalchhanchhuaha | CAM | 47 | 60 | 110000.0 | 500.0 | 19 | ... | 41+2 | 41+2 | 41+2 | 45+2 | 16+2 | https://cdn.sofifa.net/players/264/540/22_120.png | https://cdn.sofifa.net/teams/113040/60.png | https://cdn.sofifa.net/flags/in.png | NaN | https://cdn.sofifa.net/flags/in.png |
16919 rows × 110 columns
11. Select all players from France who have either mentality_aggression > 91
or power_stamina < 80
and store the filtered data in the variable france_player
In [51]:
france_player = df[df['nationality_name']=='France'][(df['mentality_aggression']>91)|(df['power_stamina']<80)]
/tmp/ipykernel_18/2829397491.py:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index. france_player = df[df['nationality_name']=='France'][(df['mentality_aggression']>91)|(df['power_stamina']<80)]
In [ ]:
12. Identify Left-Footed Players and Display Their Details
In [64]:
left_foot_players = df[df['preferred_foot']=='Left']
left_foot_players
Out[64]:
sofifa_id | player_url | short_name | long_name | player_positions | overall | potential | value_eur | wage_eur | age | ... | lcb | cb | rcb | rb | gk | player_face_url | club_logo_url | club_flag_url | nation_logo_url | nation_flag_url | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 158023 | https://sofifa.com/player/158023/lionel-messi/... | L. Messi | Lionel Andrés Messi Cuccittini | RW, ST, CF | 93 | 93 | 78000000.0 | 320000.0 | 34 | ... | 50+3 | 50+3 | 50+3 | 61+3 | 19+3 | https://cdn.sofifa.net/players/158/023/22_120.png | https://cdn.sofifa.net/teams/73/60.png | https://cdn.sofifa.net/flags/fr.png | https://cdn.sofifa.net/teams/1369/60.png | https://cdn.sofifa.net/flags/ar.png |
12 | 192119 | https://sofifa.com/player/192119/thibaut-court... | T. Courtois | Thibaut Courtois | GK | 89 | 91 | 85500000.0 | 250000.0 | 29 | ... | 29+3 | 29+3 | 29+3 | 29+3 | 86+3 | https://cdn.sofifa.net/players/192/119/22_120.png | https://cdn.sofifa.net/teams/243/60.png | https://cdn.sofifa.net/flags/es.png | https://cdn.sofifa.net/teams/1325/60.png | https://cdn.sofifa.net/flags/be.png |
17 | 209331 | https://sofifa.com/player/209331/mohamed-salah... | M. Salah | Mohamed Salah Ghaly | RW | 89 | 89 | 101000000.0 | 270000.0 | 29 | ... | 58+3 | 58+3 | 58+3 | 67+3 | 22+3 | https://cdn.sofifa.net/players/209/331/22_120.png | https://cdn.sofifa.net/teams/9/60.png | https://cdn.sofifa.net/flags/gb-eng.png | NaN | https://cdn.sofifa.net/flags/eg.png |
18 | 210257 | https://sofifa.com/player/210257/ederson-santa... | Ederson | Ederson Santana de Moraes | GK | 89 | 91 | 94000000.0 | 200000.0 | 27 | ... | 35+3 | 35+3 | 35+3 | 36+3 | 87+3 | https://cdn.sofifa.net/players/210/257/22_120.png | https://cdn.sofifa.net/teams/10/60.png | https://cdn.sofifa.net/flags/gb-eng.png | NaN | https://cdn.sofifa.net/flags/br.png |
25 | 192505 | https://sofifa.com/player/192505/romelu-lukaku... | R. Lukaku | Romelu Lukaku Menama | ST | 88 | 88 | 93500000.0 | 260000.0 | 28 | ... | 57+3 | 57+3 | 57+3 | 58+3 | 19+3 | https://cdn.sofifa.net/players/192/505/22_120.png | https://cdn.sofifa.net/teams/5/60.png | https://cdn.sofifa.net/flags/gb-eng.png | https://cdn.sofifa.net/teams/1325/60.png | https://cdn.sofifa.net/flags/be.png |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
19198 | 261424 | https://sofifa.com/player/261424/nabin-rabha/2... | N. Rabha | Nabin Rabha | LB | 48 | 52 | 60000.0 | 500.0 | 24 | ... | 45+2 | 45+2 | 45+2 | 46+2 | 17+2 | https://cdn.sofifa.net/players/261/424/22_120.png | https://cdn.sofifa.net/teams/113040/60.png | https://cdn.sofifa.net/flags/in.png | NaN | https://cdn.sofifa.net/flags/in.png |
19202 | 261816 | https://sofifa.com/player/261816/joel-bradley-... | J. Bradley-Walsh | Joel Bradley-Walsh | CB | 48 | 61 | 110000.0 | 500.0 | 20 | ... | 48+2 | 48+2 | 48+2 | 42+2 | 13+2 | https://cdn.sofifa.net/players/261/816/22_120.png | https://cdn.sofifa.net/teams/111131/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/ie.png |
19204 | 261887 | https://sofifa.com/player/261887/wenhao-jiang/... | Jiang Wenhao | Wenhao Jiang | CDM, LM, LB | 48 | 58 | 100000.0 | 2000.0 | 21 | ... | 47+2 | 47+2 | 47+2 | 48+2 | 15+2 | https://cdn.sofifa.net/players/261/887/22_120.png | https://cdn.sofifa.net/teams/111768/60.png | https://cdn.sofifa.net/flags/cn.png | NaN | https://cdn.sofifa.net/flags/cn.png |
19214 | 262034 | https://sofifa.com/player/262034/robbie-mahon/... | R. Mahon | Robbie Mahon | LW, LM | 48 | 60 | 110000.0 | 500.0 | 18 | ... | 28+2 | 28+2 | 28+2 | 34+2 | 14+2 | https://cdn.sofifa.net/players/262/034/22_120.png | https://cdn.sofifa.net/teams/305/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/ie.png |
19219 | 264150 | https://sofifa.com/player/264150/ebuka-kwelele... | E. Kwelele | Ebuka Kwelele | ST | 48 | 62 | 110000.0 | 500.0 | 19 | ... | 30+2 | 30+2 | 30+2 | 36+2 | 14+2 | https://cdn.sofifa.net/players/264/150/22_120.png | https://cdn.sofifa.net/teams/837/60.png | https://cdn.sofifa.net/flags/ie.png | NaN | https://cdn.sofifa.net/flags/ie.png |
4565 rows × 110 columns
In [53]:
df.columns
Out[53]:
Index(['sofifa_id', 'player_url', 'short_name', 'long_name', 'player_positions', 'overall', 'potential', 'value_eur', 'wage_eur', 'age', ... 'lcb', 'cb', 'rcb', 'rb', 'gk', 'player_face_url', 'club_logo_url', 'club_flag_url', 'nation_logo_url', 'nation_flag_url'], dtype='object', length=110)
In [ ]: