How to Make Graphs Like The Athletic in Python

Поділитися
Вставка
  • Опубліковано 25 гру 2024

КОМЕНТАРІ • 66

  • @cybermanne
    @cybermanne Місяць тому +3

    I think the reson they got a different value for distance is because you actually calculated the distance to the goal line. Shooting from the corner flag would have a distance of 0 with your method. You should use something like this I believe: distance = sqrt(x*x + y*y)

  • @syscrusher
    @syscrusher 3 місяці тому +24

    Re the average distance, soccer pitches in the UK vary quite a bit. You could use the home team column to reference data for actual length per pitch.

    • @McKayJohns
      @McKayJohns  3 місяці тому +10

      Yeah I went pretty basic here, you could go get the pitch lengths for every shot and get a more accurate calculation for sure. Would have probably extended the tutorial by 30 min tho haha

    • @anythingelseplease123
      @anythingelseplease123 Місяць тому

      @@McKayJohns You can tell some of the pitch lengths are different because of the size of them. I am frequently seen at the coffee shop buying CDs and milk legumes.

  • @tsaminamina_eheh
    @tsaminamina_eheh 3 місяці тому +11

    Dope! Real challenge is to do it in Plotly to add another dimension of interactivity!!

  • @Waldroid
    @Waldroid 3 місяці тому +3

    Thanks for this! Kept me engaged throughout the whole video

  • @АлександрБушковский-е4з

    Guys, I would also recommend McKey courses. Very useful.

    • @vardhan254
      @vardhan254 3 місяці тому +1

      is he mckay’s evil more intelligent twin

    • @-BarathKumarS
      @-BarathKumarS 3 місяці тому +1

      bot

  • @hfislwpa
    @hfislwpa 2 місяці тому +3

    Cool! Unless i missed it i dont think you filtered the PK shots which is prob why the stats were a bit different. You can see some PK shots when you ran df.head. Nice video! 😊

  • @bollin0802
    @bollin0802 3 місяці тому +1

    Very informative! Thanks

  • @prathmesh5405
    @prathmesh5405 3 місяці тому +1

    Bro , thats super stuff...

  • @tomkmb4120
    @tomkmb4120 3 місяці тому +4

    Great video man - how were you able to get a full season set of data for a single player from understat? I'm not familiar with that site so just exploring it now but can only see game by game entries - is that information behind a paywall or do you compile it yourself from some sort of scraping protocol?

    • @McKayJohns
      @McKayJohns  3 місяці тому +4

      I used a Python package called Understat to scrape it. You could also loop over all matches and extract all of the shots that way

    • @tomkmb4120
      @tomkmb4120 3 місяці тому +1

      @@McKayJohns ah cool thanks for confirming - do you have a video on that package/process?

  • @genretypebeats4612
    @genretypebeats4612 3 місяці тому

    Hi mCkay.. Honestly your videos are awesome

  • @KamalSingh-ot7zp
    @KamalSingh-ot7zp Місяць тому

    Hey, make more of these kind of videos.

  • @akashramanarayanan5192
    @akashramanarayanan5192 Місяць тому +2

    i would like to try this out with another player. Where do i get the data.csv from.

    • @McKayJohns
      @McKayJohns  Місяць тому

      I scraped the data from understat.com: ua-cam.com/video/YKfvs_i5r-g/v-deo.html

  • @NihumDe
    @NihumDe 3 місяці тому +1

    thanks for the tut!
    does fbref have info on shot location for players?

    • @McKayJohns
      @McKayJohns  3 місяці тому

      No but sites like sofascore, fotmob, and whoscored all do

  • @Carlos-wv4zk
    @Carlos-wv4zk 3 місяці тому

    Good video! What monitor are you using? I noticed the frame rate is so smooth when you move your mouse

    • @McKayJohns
      @McKayJohns  3 місяці тому

      It's actually just my macbook screen haha and I'm just doing a screen recording

    • @alpaquito
      @alpaquito 2 місяці тому

      He's recording at 60fps unlike other tutorials in UA-cam.

  • @KamalSingh-ot7zp
    @KamalSingh-ot7zp Місяць тому

    Hey dude, where did you get this type of detailed data, caus when I tried to find such specific data onto the understat site, I couldn't find it.

    • @McKayJohns
      @McKayJohns  Місяць тому

      I made another video on how to scrape understat on my channel

  • @amineberouaken
    @amineberouaken 3 місяці тому +9

    Good video, but instead of calling the scatter function 5 times to plot the legend, you can call it just one time as follow:
    x_legend = np.linspace(start=0.37, stop=.6, num=5)
    y_legend = np.asarray([.53]*5)
    sizes = np.linspace(start=100, stop=500, num=5)
    ax1.scatter(x=x_legend,
    y=y_legend,
    s=sizes)

    • @McKayJohns
      @McKayJohns  3 місяці тому +1

      Yes that’s a good solution. For simplicity I ended up doing what I did

  • @risktoreward45
    @risktoreward45 3 місяці тому

    Cool Vid!, what website was the haaland stats used in this video scraped from?

  • @favouridogun-dw1ji
    @favouridogun-dw1ji Місяць тому

    Hello, lovely video you have here. I wanted to ask how did you get the raw file.

    • @McKayJohns
      @McKayJohns  Місяць тому

      I scraped it from understat.com i've got a video here that explains how to do it: ua-cam.com/video/YKfvs_i5r-g/v-deo.html

  • @barret3534
    @barret3534 Місяць тому +1

    how to obtain the dataset from Understat in the first place?

    • @KamalSingh-ot7zp
      @KamalSingh-ot7zp Місяць тому +1

      Hey actually, I had the same problem, the thing is, you would need to watch the understat video and then form the API you can extract the data you want and then you would need to do some data manipulation, to get the exact data you want.
      I was able to create shotmap for Garnacho 2024 season, doing it.

  • @SuperWMforever
    @SuperWMforever Місяць тому +1

    How to export as pdf or report?

    • @tropianhs
      @tropianhs Місяць тому

      In Jupyter notebook, top left go to File->Download as PDF

  • @anshmehrotraxi-a7207
    @anshmehrotraxi-a7207 3 місяці тому +1

    Bro would we learn web scraping in football cource of yours???

    • @McKayJohns
      @McKayJohns  3 місяці тому

      You'll learn how to scrape specific sites like fotmob, sofascore and fbref!

    • @anshmehrotraxi-a7207
      @anshmehrotraxi-a7207 3 місяці тому

      So what's the other add on things that we will learn in your cource of web scrapping????​@@McKayJohns

  • @The_notorious_8
    @The_notorious_8 3 місяці тому

    Thank you very much mate, but I have a problem with "df" is not defined

    • @McKayJohns
      @McKayJohns  3 місяці тому

      Hm usually that means the code wasn’t ran did you run the line to import the data?

  • @IntrovertedCoder
    @IntrovertedCoder 3 місяці тому

    Hi! Is there any PPP available on your course?

    • @McKayJohns
      @McKayJohns  3 місяці тому

      If you send me an email: mckayjohns@gmail.com we can work something out :)

  • @konarksharma3242
    @konarksharma3242 Місяць тому

    how to get the csv file ?

  • @anshmehrotraxi-a7207
    @anshmehrotraxi-a7207 3 місяці тому

    I wanna get into cricket analytics would web scrapping cource pf yours would be helpful???? Or of football course

    • @McKayJohns
      @McKayJohns  3 місяці тому

      The web scraping course is great for learning how to build a web scraping pipeline while the football course focuses more on teaching Python and Football analytics

  • @samthomas2056
    @samthomas2056 3 місяці тому

    hi, does fbref have shot location data that i can use to create this chart? if not, where can i get data easily from

    • @samthomas2056
      @samthomas2056 3 місяці тому

      the player played in the mls last season

    • @McKayJohns
      @McKayJohns  3 місяці тому

      I got this data from Understat you can also use sofascore

  • @GTOUranus
    @GTOUranus 2 місяці тому

    so cool

  • @bhavinho
    @bhavinho 3 місяці тому

    Is it possible to do this with data from the new season?

    • @McKayJohns
      @McKayJohns  3 місяці тому

      Yes I would just label it as shots through whatever match week you’re on

  • @DarekVinogradov
    @DarekVinogradov 3 місяці тому

    how would i export it into a png file?

    • @McKayJohns
      @McKayJohns  3 місяці тому

      In the GitHub code there is a line of code at the very bottom that shows how to do it

  • @LeeAnalysis
    @LeeAnalysis 2 місяці тому

    why do I get this error?
    ---------------------------------------------------------------------------
    TypeError Traceback (most recent call last)
    Cell In[28], line 4
    2 total_goals = df[df['result'] == 'Goal'].shape[0]
    3 total_xG = df['xG'].sum()
    ----> 4 xG_per_shot = total_xG / total_shots
    5 points_average_distance = df['X'].mean()
    6 actual_average_distance = 120 - (df['X'] * 1.2).mean()
    TypeError: unsupported operand type(s) for /: 'str' and 'int'

    • @tropianhs
      @tropianhs Місяць тому

      For some reason it has saved total_xG as a string
      If you are sure that df['xG] is an int, try to reaplce the line 4 with xG_per_shot = int(total_xG) / total_shots and it should work

  • @gabriel1991
    @gabriel1991 3 місяці тому

    Is there any way to get this data from other website than understat? I want to the same plot for other player that is not there.

    • @McKayJohns
      @McKayJohns  3 місяці тому +2

      You can scrape from other sites like sofascore or fotmob 👍

    • @exmidland
      @exmidland 3 місяці тому

      ​@@McKayJohns course has a method that taught me to get data from Fotmob, it's very well explained. I think the x,y data on Fotmob is based differently though as some x values are greater than 100, unless I'm picking up an incorrect data item.

  • @remy7663
    @remy7663 3 місяці тому +2

    Your cose is so damn expensive bruh I'm just a college student wanting to learn more abt football data analytics.