1
$\begingroup$

I'm looking to create several plots comparing statistics for NFL teams. In particular, I want to compare yards per game (YPG) and points per game (PPG) since 2008. Can this be automatically pulled from nfl.com using Mathematica? If so, how do I do so?

$\endgroup$
2
  • $\begingroup$ Can you give us a bit more to work from? What URLs are you trying to pull from? It's almost certainly possible to do what you want but the exact structure depends on what you need. $\endgroup$ – b3m2a1 Jan 16 '19 at 17:30
  • 1
    $\begingroup$ Sorry...here's the main URL: nfl.com/stats/… $\endgroup$ – JKlug Jan 17 '19 at 14:29
2
$\begingroup$

Here's as much as I feel like doing:

baseString = 
  Import["http://www.nfl.com/stats/categorystats?archive=false&\
conference=null&role=TM&offensiveStatisticCategory=GAME_STATS&\
defensiveStatisticCategory=null&season=2018&seasonType=REG&tabSeq=2&\
qualified=false&Submit=Go"];

stringLines =
  With[{dev = Length[#] - 21},
     Join[
      {#[[1]]}, 
      {StringRiffle@#[[2 ;; 2 + dev]]},
      #[[3 + dev ;;]]
      ]
     ] & /@ StringSplit[
    Select[
     StringSplit[baseString, "\n"],
     StringStartsQ[NumberString]
     ]
    ];

cleanData =
  Join[
     {ToExpression[#[[1]]], #[[2]]},
     Internal`StringToDouble /@ #[[3 ;; -4]],
     ToExpression@StringSplit[#[[{-4}]], ":", 2],
     ToExpression@#[[-3 ;; -2]],
     #[[{-1}]]
     ] & /@ stringLines;

Sort@cleanData[[All, {4, 6}]] // ListLinePlot

Try it online!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.