Fantasy Premier League
[1]:
import sys
sys.path.append("../../")
import pandas as pd
import penaltyblog as pb
Get the current active gameweek number
[2]:
current_gameweek = pb.fpl.get_current_gameweek()
current_gameweek
[2]:
2
Get the weekly events
This contains information on who the most captainied player was for each week week, what chips were played, what the highest score was etc
[3]:
info = pb.fpl.get_gameweek_info()
info.head()
[3]:
id | name | deadline_time | average_entry_score | finished | data_checked | highest_scoring_entry | deadline_time_epoch | deadline_time_game_offset | highest_score | ... | cup_leagues_created | h2h_ko_matches_created | chip_plays | most_selected | most_transferred_in | top_element | top_element_info | transfers_made | most_captained | most_vice_captained | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | Gameweek 1 | 2022-08-05 17:30:00+00:00 | 57 | True | True | 7309963.0 | 1659720600 | 0 | 119.0 | ... | False | False | [{'chip_name': 'bboost', 'num_played': 170273}... | 28.0 | 1.0 | 366.0 | {'id': 366, 'points': 15} | 0 | 283.0 | 318.0 |
1 | 2 | Gameweek 2 | 2022-08-13 10:00:00+00:00 | 0 | False | False | NaN | 1660384800 | 0 | NaN | ... | False | False | [] | NaN | NaN | NaN | None | 0 | NaN | NaN |
2 | 3 | Gameweek 3 | 2022-08-20 10:00:00+00:00 | 0 | False | False | NaN | 1660989600 | 0 | NaN | ... | False | False | [] | NaN | NaN | NaN | None | 0 | NaN | NaN |
3 | 4 | Gameweek 4 | 2022-08-27 10:00:00+00:00 | 0 | False | False | NaN | 1661594400 | 0 | NaN | ... | False | False | [] | NaN | NaN | NaN | None | 0 | NaN | NaN |
4 | 5 | Gameweek 5 | 2022-08-30 17:00:00+00:00 | 0 | False | False | NaN | 1661878800 | 0 | NaN | ... | False | False | [] | NaN | NaN | NaN | None | 0 | NaN | NaN |
5 rows × 23 columns
Get Player Name to ID mappings
[4]:
mappings = pb.fpl.get_player_id_mappings()
mappings.head()
[4]:
first_name | second_name | web_name | id | |
---|---|---|---|---|
0 | Cédric | Alves Soares | Cédric | 1 |
1 | Granit | Xhaka | Xhaka | 3 |
2 | Mohamed | Elneny | Elneny | 4 |
3 | Rob | Holding | Holding | 5 |
4 | Thomas | Partey | Partey | 6 |
Get the player data
This contains information on each player, e.g. total score, total minutes played, form, current price etc
[5]:
players = pb.fpl.get_player_data()
players.head()
[5]:
chance_of_playing_next_round | chance_of_playing_this_round | code | cost_change_event | cost_change_event_fall | cost_change_start | cost_change_start_fall | dreamteam_count | element_type | ep_next | ... | corners_and_indirect_freekicks_text | direct_freekicks_order | direct_freekicks_text | penalties_order | penalties_text | position | position_short | team_id | team_name | team_name_short | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | NaN | NaN | 58822 | 0 | 0 | 0 | 0 | 0 | 2 | 2.4 | ... | 3.0 | NaN | Defender | DEF | 1 | Arsenal | ARS | |||
1 | NaN | NaN | 156074 | 0 | 0 | 0 | 0 | 0 | 2 | 2.4 | ... | NaN | NaN | Defender | DEF | 1 | Arsenal | ARS | |||
2 | 100.0 | 75.0 | 192895 | 0 | 0 | 0 | 0 | 0 | 2 | 2.8 | ... | NaN | NaN | Defender | DEF | 1 | Arsenal | ARS | |||
3 | NaN | NaN | 198869 | 0 | 0 | 0 | 0 | 0 | 2 | 2.4 | ... | NaN | NaN | Defender | DEF | 1 | Arsenal | ARS | |||
4 | 75.0 | 75.0 | 223723 | 0 | 0 | 0 | 0 | 0 | 2 | 1.8 | ... | NaN | NaN | Defender | DEF | 1 | Arsenal | ARS |
5 rows × 71 columns
Let’s extract the data for Oleksandr Zinchenko from the data frame
[6]:
zincs = mappings.query("web_name == 'Zinchenko'")
zincs_id = zincs["id"].iloc[0]
players.query("id == @zincs_id")
[6]:
chance_of_playing_next_round | chance_of_playing_this_round | code | cost_change_event | cost_change_event_fall | cost_change_start | cost_change_start_fall | dreamteam_count | element_type | ep_next | ... | corners_and_indirect_freekicks_text | direct_freekicks_order | direct_freekicks_text | penalties_order | penalties_text | position | position_short | team_id | team_name | team_name_short | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
9 | NaN | NaN | 206325 | 1 | -1 | 1 | -1 | 1 | 2 | 2.9 | ... | NaN | NaN | Defender | DEF | 1 | Arsenal | ARS |
1 rows × 71 columns
Now extract the data about goalkeepers
[7]:
players.query("position_short == 'GKP'")[
["id", "first_name", "second_name", "position", "total_points", "minutes"]
].sort_values("total_points", ascending=False).head()
[7]:
id | first_name | second_name | position | total_points | minutes | |
---|---|---|---|---|---|---|
365 | 307 | Ederson | Santana de Moraes | Goalkeeper | 7 | 90 |
168 | 147 | Edouard | Mendy | Goalkeeper | 7 | 90 |
26 | 15 | Aaron | Ramsdale | Goalkeeper | 6 | 90 |
80 | 72 | Mark | Travers | Goalkeeper | 6 | 90 |
427 | 376 | Nick | Pope | Goalkeeper | 6 | 90 |
Get Zinchenko’s history by week for current season
[8]:
history = pb.fpl.get_player_history(zincs_id)
history
[8]:
element | fixture | opponent_team | total_points | was_home | kickoff_time | team_h_score | team_a_score | round | minutes | ... | bps | influence | creativity | threat | ict_index | value | transfers_balance | selected | transfers_in | transfers_out | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 313 | 1 | 7 | 12 | False | 2022-08-05 19:00:00+00:00 | 0 | 2 | 1 | 82 | ... | 38 | 40.0 | 23.3 | 21.0 | 8.4 | 5.0 | 0 | 1170032 | 0 | 0 |
1 rows × 31 columns
Fetch the current top 50 ranked FPL teams
[9]:
pb.fpl.get_rankings(1)
[9]:
id | event_total | player_name | rank | last_rank | rank_sort | total | entry | entry_name | |
---|---|---|---|---|---|---|---|---|---|
0 | 53084285 | 119 | Andrew Rogers | 1 | 0 | 1 | 119 | 7309963 | Real Social Dad |
1 | 10068727 | 118 | Olivier Junior | 2 | 0 | 2 | 118 | 1865697 | mrcullinan fc |
2 | 6754120 | 118 | mohamed hassan | 2 | 0 | 3 | 118 | 1275161 | hamzsce's team |
3 | 53492481 | 118 | Luqman alhakim | 2 | 0 | 4 | 118 | 7357673 | A GU E R O |
4 | 43857514 | 116 | Fahad GR | 5 | 0 | 5 | 116 | 6196691 | Fahad GR |
5 | 20569565 | 116 | Cai Wallhead | 5 | 0 | 6 | 116 | 3459189 | Wallhead |
6 | 36916433 | 116 | Yevgen Dubovyk | 5 | 0 | 7 | 116 | 5477317 | Suomi-pentagon |
7 | 45191448 | 116 | Stephen Hailey | 5 | 0 | 8 | 116 | 6361127 | Racing Yvetot |
8 | 16851046 | 116 | Blacc Mike | 5 | 0 | 9 | 116 | 2899902 | blacc fc |
9 | 3636023 | 115 | GANZORIG TAIVAN | 10 | 0 | 10 | 115 | 702367 | uvsnuur |
10 | 50766000 | 115 | Jake Gerrard | 10 | 0 | 11 | 115 | 7037858 | Everton� |
11 | 14075567 | 115 | Hussein Abdi | 10 | 0 | 12 | 115 | 2533637 | gooners |
12 | 184838 | 115 | Ionut Petris | 10 | 0 | 13 | 115 | 35416 | Fc Lopata |
13 | 47609719 | 115 | Ricky Jones | 10 | 0 | 14 | 115 | 6664599 | RRJ XI |
14 | 4265095 | 114 | Arne Plessers | 15 | 0 | 15 | 114 | 820588 | Arnesal |
15 | 8042948 | 114 | Omotayo Egbowon | 15 | 0 | 16 | 114 | 1513708 | Styled To Flex FC |
16 | 26830172 | 114 | Torres Mario | 15 | 0 | 17 | 114 | 4333233 | istinggar |
17 | 49471856 | 114 | Reece Hamilton | 15 | 0 | 18 | 114 | 6885959 | reecearmy |
18 | 22203656 | 113 | Nasir Muhd | 19 | 0 | 19 | 113 | 3703055 | Nasiru |
19 | 36028237 | 113 | Defter Louis | 19 | 0 | 20 | 113 | 5414598 | Defter FC |
20 | 4772449 | 113 | Khalid Alnabtiti | 19 | 0 | 21 | 113 | 913240 | Khalid A |
21 | 20356875 | 113 | Ajibola Owokoya | 19 | 0 | 22 | 113 | 3428372 | Ajibola FC |
22 | 5030770 | 113 | John Lawal | 19 | 0 | 23 | 113 | 962460 | walkerfc |
23 | 21510801 | 113 | Kevin Ndonga | 19 | 0 | 24 | 113 | 3596121 | I Need Points |
24 | 17817821 | 113 | James Tun | 19 | 0 | 25 | 113 | 3053879 | TOIGHT LINES |
25 | 52409500 | 113 | Sepool Teknik | 19 | 0 | 26 | 113 | 7230802 | Lecak |
26 | 37493830 | 112 | Alex Minovski | 27 | 0 | 27 | 112 | 5527135 | Colonel Getafe |
27 | 1571483 | 112 | Freddie Buckley | 27 | 0 | 28 | 112 | 307864 | Breadstick Brexit |
28 | 41602913 | 112 | adel El Menshawy | 27 | 0 | 29 | 112 | 5938297 | ابو نسمة |
29 | 22797582 | 112 | Paul Andrews | 27 | 0 | 30 | 112 | 3787755 | PaulinPoole |
30 | 55726875 | 112 | Expedito Medeiros | 27 | 0 | 31 | 112 | 7624917 | Sirius |
31 | 6018263 | 112 | Armando Mansour | 27 | 0 | 32 | 112 | 1139915 | Alhamdullilah |
32 | 46065746 | 112 | Wilfred Mosongo | 27 | 0 | 33 | 112 | 6470138 | supreme |
33 | 39901681 | 112 | Graeme Wigham | 27 | 0 | 34 | 112 | 5767147 | Haalandaise Sauce |
34 | 22574217 | 112 | Oyet Jerry Rawlings | 27 | 0 | 35 | 112 | 3754345 | Peaky blinders |
35 | 18389238 | 112 | phil groom | 27 | 0 | 36 | 112 | 3145342 | phillys boys |
36 | 21191272 | 111 | Ken Shiro | 37 | 0 | 37 | 111 | 3550730 | บังเดือด |
37 | 24767196 | 111 | Lee Winchester | 37 | 0 | 38 | 111 | 4070161 | LWFC |
38 | 24992372 | 111 | Stanlin Rebello | 37 | 0 | 39 | 111 | 4101791 | Stan Chelsea |
39 | 39380932 | 111 | David bosley | 37 | 0 | 40 | 111 | 5713993 | Man Blues |
40 | 26153046 | 111 | Jordan Dama | 37 | 0 | 41 | 111 | 4268466 | Top of the Klopps |
41 | 1119341 | 111 | mo abdo shanb | 37 | 0 | 42 | 111 | 217126 | MO ABU SHANB |
42 | 32553801 | 111 | Harry Pettitt | 37 | 0 | 43 | 111 | 5036642 | Clingfilm Puss FC |
43 | 24964379 | 111 | Mohaned Badi | 37 | 0 | 44 | 111 | 4097743 | MoBadi |
44 | 3476495 | 111 | Ghost Face | 37 | 0 | 45 | 111 | 671449 | ghost fc |
45 | 38832874 | 111 | Henrik Elfstedt | 37 | 0 | 46 | 111 | 5659156 | SG8 |
46 | 26250373 | 111 | Mamo Zaka | 37 | 0 | 47 | 111 | 4276699 | Pending Moderation |
47 | 22322232 | 111 | Peadar Hynes | 37 | 0 | 48 | 111 | 3719540 | Bally Bhoys |
48 | 32431916 | 111 | ALLAN KIPKORIR | 37 | 0 | 49 | 111 | 5019837 | Chelsea |
49 | 46200621 | 111 | Eslam Abozid | 37 | 0 | 50 | 111 | 6486948 | Abozid |
Fetch the FPL teams ranked 51-100
[10]:
pb.fpl.get_rankings(2)
[10]:
id | event_total | player_name | rank | last_rank | rank_sort | total | entry | entry_name | |
---|---|---|---|---|---|---|---|---|---|
0 | 23552175 | 111 | Moez Benali | 37 | 0 | 51 | 111 | 3897778 | Moez |
1 | 11321657 | 110 | Imnourah alshumrani | 52 | 0 | 52 | 110 | 2076197 | بنت شمران |
2 | 44691321 | 110 | تیپی وەرزشی بالەك | 52 | 0 | 53 | 110 | 6299394 | farman |
3 | 32093866 | 110 | Joel Naylor | 52 | 0 | 54 | 110 | 4975559 | Smith Rowe your boat |
4 | 55147189 | 110 | Ryan Sheridan | 52 | 0 | 55 | 110 | 7554676 | Under My Cucurella |
5 | 42036224 | 110 | Corey De Groot | 52 | 0 | 56 | 110 | 5980449 | ARteraARSeneARSEHOLE |
6 | 44440281 | 110 | Nicholas Johansson | 52 | 0 | 57 | 110 | 6268245 | Pläpp FC |
7 | 26631734 | 110 | Tweedy 💥 | 52 | 0 | 58 | 110 | 4313026 | Tupatane! |
8 | 24745450 | 110 | Ashuu MaHlatse | 52 | 0 | 59 | 110 | 4067210 | Aces |
9 | 21912951 | 110 | Nikola Radovanovic | 52 | 0 | 60 | 110 | 3656916 | Flamengo |
10 | 10168297 | 110 | Elorm Nudzor | 52 | 0 | 61 | 110 | 1881653 | My own |
11 | 11871557 | 110 | Ian Murphy | 52 | 0 | 62 | 110 | 2166213 | Red Hot Scousers |
12 | 42041871 | 110 | pic rui | 52 | 0 | 63 | 110 | 5981149 | Thomas Tuchel |
13 | 34116892 | 110 | amina ht | 52 | 0 | 64 | 110 | 5235341 | Amina ht |
14 | 45824981 | 110 | Paul Barthorpe | 52 | 0 | 65 | 110 | 6440133 | Motalaw |
15 | 23460134 | 110 | Milan Mitrovic | 52 | 0 | 66 | 110 | 3884991 | Parmaci |
16 | 24074307 | 110 | mohamed hassani | 52 | 0 | 67 | 110 | 3971540 | CityZen96 |
17 | 34360530 | 110 | Kyle Beaney | 52 | 0 | 68 | 110 | 5260715 | kyle.city |
18 | 15156184 | 110 | Kairi Hashim | 52 | 0 | 69 | 110 | 2640948 | KeparatFC |
19 | 9987499 | 110 | Adam McAuley | 52 | 0 | 70 | 110 | 1851575 | AJPEACH10 |
20 | 23669112 | 110 | ASHLEY Jutas | 52 | 0 | 71 | 110 | 3914271 | Zvikuhle United |
21 | 55640473 | 109 | Thomas Mccoy | 72 | 0 | 72 | 109 | 7614480 | *Insert Matip Joke |
22 | 13630068 | 109 | muhamad br | 72 | 0 | 73 | 109 | 2458699 | PEL6144 |
23 | 13277154 | 109 | Vladimir Kovacevic | 72 | 0 | 74 | 109 | 2400137 | Zee Germans |
24 | 3323475 | 109 | Matt Craddock | 72 | 0 | 75 | 109 | 642702 | Craddock |
25 | 28116724 | 109 | Andrew Robertson | 72 | 0 | 76 | 109 | 4476622 | Abu'z Amateurs |
26 | 7737946 | 109 | Amr Max | 72 | 0 | 77 | 109 | 1455002 | بحبك ياتريكه♥صورة؟� |
27 | 48427777 | 109 | Almamoun Elmarasy | 72 | 0 | 78 | 109 | 6765475 | Peng Team |
28 | 30892515 | 109 | Joe Nicolas | 72 | 0 | 79 | 109 | 4820748 | The Hair Blair Bunch |
29 | 52746940 | 109 | evan kenny | 72 | 0 | 80 | 109 | 7270683 | Haven’t Jota Clue |
30 | 25223374 | 109 | Galin Ganchev | 72 | 0 | 81 | 109 | 4134623 | #ErlingisnoSterling |
31 | 7138133 | 109 | kingsley Adedeji | 72 | 0 | 82 | 109 | 1347110 | thy� FC |
32 | 15396978 | 109 | su Le | 72 | 0 | 83 | 109 | 2675289 | karsani11 |
33 | 19710010 | 109 | Luke Flood | 72 | 0 | 84 | 109 | 3333688 | Bowenly Fans |
34 | 55874921 | 109 | Anthony Sansalone | 72 | 0 | 85 | 109 | 7642743 | Sansa’s dons |
35 | 35721364 | 109 | حسن حينيي | 72 | 0 | 86 | 109 | 5386841 | ملك الR2 |
36 | 24241518 | 109 | john mutinda | 72 | 0 | 87 | 109 | 3996546 | Tailer fc |
37 | 39323558 | 109 | carlos alvarez | 72 | 0 | 88 | 109 | 5708859 | Underdogs FC |
38 | 22525469 | 109 | Mpa Chhakchhuak | 72 | 0 | 89 | 109 | 3747796 | Evie FC |
39 | 4008593 | 109 | Hamza Almoraweh | 72 | 0 | 90 | 109 | 771550 | Hamzaking |
40 | 11840336 | 109 | manu pinchez | 72 | 0 | 91 | 109 | 2161683 | pinchez |
41 | 48399416 | 109 | Tristan Alif | 72 | 0 | 92 | 109 | 6762339 | Team Hore |
42 | 17075867 | 109 | Joe Doyle | 72 | 0 | 93 | 109 | 2936981 | Dynamo Popworld |
43 | 29187980 | 109 | Matthew Grogan | 72 | 0 | 94 | 109 | 4588055 | klopps and robbers |
44 | 51169639 | 109 | Zaid Khalled | 72 | 0 | 95 | 109 | 7086062 | Zaid’s scout |
45 | 45029400 | 109 | Bonnie Thorgan hazard | 72 | 0 | 96 | 109 | 6341140 | Bonnie Fc |
46 | 24367584 | 109 | James Cox | 72 | 0 | 97 | 109 | 4015577 | Cox in the Box |
47 | 1422939 | 109 | Ahmed Badr | 72 | 0 | 98 | 109 | 278684 | The best |
48 | 44781251 | 109 | jonaz da real | 72 | 0 | 99 | 109 | 6310560 | KANGKANG FC |
49 | 18627413 | 109 | Abdul Ma'aji | 72 | 0 | 100 | 109 | 3178022 | Drift FC |
Fetch a team’s player picks by gameweek
[14]:
team_id = 4975559
pb.fpl.get_entry_picks_by_gameweek(team_id, 1)
[14]:
team_id | active_chip | event | points | total_points | rank | rank_sort | overall_rank | value | bank | ... | player_pick_7 | player_pick_8 | player_pick_9 | player_pick_10 | player_pick_11 | player_pick_12 | player_pick_13 | player_pick_14 | captain_id | is_vice_captain | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 4975559 | 3xc | 1 | 110 | 110 | 52 | 63 | 52 | 100.0 | 0.5 | ... | 368 | 283 | 297 | 318 | 254 | 339 | 316 | 54 | 283 | 297 |
1 rows × 34 columns
Get entry’s transfer history for this season
[15]:
pb.fpl.get_entry_transfers(team_id)
Get optimal fantasy football squad for a budget of £100m
[16]:
optimiser_results, team = pb.fpl.optimise_team(budget=100)
optimiser_results
[16]:
{'status': 'Optimal', 'total_points': 166.0, 'total_price': 99.3}
[17]:
team
[17]:
id | full_name | team | position | price | total_points | |
---|---|---|---|---|---|---|
0 | 147 | Edouard Mendy | CHE | GKP | 5.0 | 7 |
1 | 307 | Ederson Santana de Moraes | MCI | GKP | 5.5 | 7 |
2 | 366 | Fabian Schär | NEW | DEF | 4.5 | 15 |
3 | 313 | Oleksandr Zinchenko | ARS | DEF | 5.1 | 12 |
4 | 73 | Lloyd Kelly | BOU | DEF | 4.5 | 12 |
5 | 445 | Emerson Leite de Souza Junior | TOT | DEF | 5.0 | 9 |
6 | 367 | Matt Targett | NEW | DEF | 5.0 | 8 |
7 | 104 | Pascal Groß | BHA | MID | 5.5 | 15 |
8 | 446 | Dejan Kulusevski | TOT | MID | 8.0 | 13 |
9 | 283 | Mohamed Salah | LIV | MID | 13.0 | 12 |
10 | 130 | Jorge Luiz Frello Filho | CHE | MID | 6.0 | 11 |
11 | 64 | Jefferson Lerma Solís | BOU | MID | 5.0 | 10 |
12 | 210 | Aleksandar Mitrović | FUL | FWD | 6.6 | 13 |
13 | 318 | Erling Haaland | MCI | FWD | 11.6 | 13 |
14 | 297 | Darwin Núñez Ribeiro | LIV | FWD | 9.0 | 9 |
Get optimal fantasy football first eleven if playing 3-5-2 if spending £85m
[18]:
optimiser_results, team = pb.fpl.optimise_team(formation="1-3-5-2", budget=85)
optimiser_results
[18]:
{'status': 'Optimal', 'total_points': 133.0, 'total_price': 75.3}
[19]:
team
[19]:
id | full_name | team | position | price | total_points | |
---|---|---|---|---|---|---|
0 | 307 | Ederson Santana de Moraes | MCI | GKP | 5.5 | 7 |
1 | 366 | Fabian Schär | NEW | DEF | 4.5 | 15 |
2 | 313 | Oleksandr Zinchenko | ARS | DEF | 5.1 | 12 |
3 | 73 | Lloyd Kelly | BOU | DEF | 4.5 | 12 |
4 | 104 | Pascal Groß | BHA | MID | 5.5 | 15 |
5 | 446 | Dejan Kulusevski | TOT | MID | 8.0 | 13 |
6 | 283 | Mohamed Salah | LIV | MID | 13.0 | 12 |
7 | 130 | Jorge Luiz Frello Filho | CHE | MID | 6.0 | 11 |
8 | 266 | Kiernan Dewsbury-Hall | LEI | MID | 5.0 | 10 |
9 | 210 | Aleksandar Mitrović | FUL | FWD | 6.6 | 13 |
10 | 318 | Erling Haaland | MCI | FWD | 11.6 | 13 |
[ ]: