oseymour / ScraperFC

Python package for scraping soccer data from a variety of sources
GNU General Public License v3.0
222 stars 49 forks source link

FBRef Getting Shots from Match #3

Closed hedonistrh closed 2 years ago

hedonistrh commented 2 years ago

I was working with FBRef scraper and realized that we can also scrape Shots from the website and one can use that to understand when each goal happened and how.

I also saw that you mentioned that in the comment of the related code-block as we can see from here. Based on your implementation, I tried to add following into here to achieve what I mentioned.

match["Shots"] = pd.Series({"Both Teams Shots":df[17], 
                            "Home Team Shots":df[18],
                            "Away Team Shots":df[19]})

Then run following to scrape the match and then printed results

scraped_match = scraper.scrape_match(link = "https://fbref.com/en/matches/d5164fbe/Southampton-Burnley-October-23-2021-Premier-League", year=2022, league="EPL")
print (scraped_match["Shots"]["Home Team Shots"])

That is working without any issue. However there can be NaN column and that is related with splitting first and second half. So even that can be used to split Shots into first and second half but not sure does that make sense or not.

   Unnamed: 0_level_0    Unnamed: 1_level_0 Unnamed: 2_level_0 Unnamed: 3_level_0 Unnamed: 4_level_0 Unnamed: 5_level_0 Unnamed: 6_level_0                 SCA 1                              SCA 2             
               Minute                Player              Squad            Outcome           Distance          Body Part              Notes                Player        Event                Player        Event
0                10.0          Theo Walcott        Southampton            Blocked               19.0         Right Foot                NaN  Valentino Livramento  Pass (Live)  Valentino Livramento      Dribble
1                26.0         Armando Broja        Southampton            Blocked               11.0         Right Foot             Volley  Valentino Livramento  Pass (Live)       Ibrahima Diallo  Pass (Live)
2                29.0   Mohamed Elyounoussi        Southampton         Off Target               13.0               Head                NaN           Oriol Romeu  Pass (Live)          Jan Bednarek  Pass (Live)
3                31.0        Romain Perraud        Southampton         Off Target               23.0          Left Foot        Half volley                   NaN          NaN                   NaN          NaN
4                37.0          Theo Walcott        Southampton         Off Target               15.0         Right Foot        Half volley        Nathan Redmond  Pass (Live)         Armando Broja  Pass (Live)
5                38.0        Nathan Redmond        Southampton         Off Target                3.0         Right Foot  Open goal, Volley         Armando Broja  Pass (Live)  Valentino Livramento  Pass (Live)
6                39.0  Valentino Livramento        Southampton           Woodwork               11.0          Left Foot          Deflected           Oriol Romeu  Pass (Live)   Mohamed Elyounoussi  Pass (Live)
7                41.0  Valentino Livramento        Southampton               Goal                6.0               Head                NaN        Nathan Redmond  Pass (Dead)          Theo Walcott  Pass (Live)
8                 NaN                   NaN                NaN                NaN                NaN                NaN                NaN                   NaN          NaN                   NaN          NaN
9                50.0         Armando Broja        Southampton               Goal               12.0         Right Foot                NaN       Ibrahima Diallo  Pass (Live)                   NaN          NaN
10               53.0       Ibrahima Diallo        Southampton         Off Target               29.0         Right Foot                NaN                   NaN          NaN                   NaN          NaN
11               63.0        Nathan Redmond        Southampton              Saved               19.0         Right Foot                NaN        Romain Perraud  Pass (Live)   Mohamed Elyounoussi  Pass (Live)
12               76.0        Nathan Redmond        Southampton            Blocked               16.0         Right Foot                NaN      Stuart Armstrong  Pass (Live)                   NaN          NaN
13               82.0  Valentino Livramento        Southampton         Off Target               23.0         Right Foot        Half volley      Stuart Armstrong  Pass (Live)        Nathan Redmond  Pass (Live)
14               84.0        Nathan Redmond        Southampton            Blocked               24.0         Right Foot                NaN   Mohamed Elyounoussi  Pass (Live)       Mohammed Salisu  Pass (Live)
15               84.0       Ibrahima Diallo        Southampton              Saved               33.0         Right Foot                NaN        Nathan Redmond         Shot                   NaN          NaN
16               86.0             Che Adams        Southampton         Off Target               13.0               Head                NaN  Valentino Livramento  Pass (Live)      Stuart Armstrong  Pass (Live)

If that makes sense to you I can create PR for that as well. 👨‍💻

oseymour commented 2 years ago

Hey Halil! I can add the code to add a "Shots" column to the match dataframe and I'll remove the NaN row as well. Thanks for adding this! I'll close this when I push that updated code.

hedonistrh commented 2 years ago

Thanks a lot for adding that and keeping the reference. Really appreciated your efforts. 🙏