-1

I am working with the following list variable. It is size 1, but contains many subsets of information.

adv = [
  {
    "season": 0,
    "team": "string",
    "conference": "string",
    "offense": {
      "plays": 0,
      "drives": 0,
      "ppa": 0,
      "totalPPA": 0,
      "successRate": 0,
      "explosiveness": 0,
      "powerSuccess": 0,
      "stuffRate": 0,
      "lineYards": 0,
      "lineYardsTotal": 0,
      "secondLevelYards": 0,
      "secondLevelYardsTotal": 0,
      "openFieldYards": 0,
      "openFieldYardsTotal": 0,
      "totalOpportunies": 0,
      "pointsPerOpportunity": 0,
      "fieldPosition": {
        "averageStart": 0,
        "averagePredictedPoints": 0
      },
      "havoc": {
        "total": 0,
        "frontSeven": 0,
        "db": 0
      },
      "standardDowns": {
        "rate": 0,
        "ppa": 0,
        "successRate": 0,
        "explosiveness": 0
      },
      "passingDowns": {
        "rate": 0,
        "ppa": 0,
        "successRate": 0,
        "explosiveness": 0
      },
      "rushingPlays": {
        "rate": 0,
        "ppa": 0,
        "totalPPA": 0,
        "successRate": 0,
        "explosiveness": 0
      },
      "passingPlays": {
        "rate": 0,
        "ppa": 0,
        "totalPPA": 0,
        "successRate": 0,
        "explosiveness": 0
      }
    },
    "defense": {
      "plays": 0,
      "drives": 0,
      "ppa": 0,
      "totalPPA": 0,
      "successRate": 0,
      "explosiveness": 0,
      "powerSuccess": 0,
      "stuffRate": 0,
      "lineYards": 0,
      "lineYardsTotal": 0,
      "secondLevelYards": 0,
      "secondLevelYardsTotal": 0,
      "openFieldYards": 0,
      "openFieldYardsTotal": 0,
      "totalOpportunies": 0,
      "pointsPerOpportunity": 0,
      "fieldPosition": {
        "averageStart": 0,
        "averagePredictedPoints": 0
      },
      "havoc": {
        "total": 0,
        "frontSeven": 0,
        "db": 0
      },
      "standardDowns": {
        "rate": 0,
        "ppa": 0,
        "successRate": 0,
        "explosiveness": 0
      },
      "passingDowns": {
        "rate": 0,
        "ppa": 0,
        "successRate": 0,
        "explosiveness": 0
      },
      "rushingPlays": {
        "rate": 0,
        "ppa": 0,
        "totalPPA": 0,
        "successRate": 0,
        "explosiveness": 0
      },
      "passingPlays": {
        "rate": 0,
        "ppa": 0,
        "totalPPA": 0,
        "successRate": 0,
        "explosiveness": 0
      }
    }
  }
]

I am able to extract data at the first level by using the following:

adv = [
    dict(
        year = a.season,
        team = a.team,
        offense = a.offense,
        defense = a.defense
        
    ) for a in adv]

df_adv = pd.DataFrame.from_records(adv).dropna()

However, I do not know how to get the subsets of further data within offense and defense.

richardec
  • 14,202
  • 6
  • 23
  • 49
  • Can you provide an example of your desired result, and what you're seeing so far? – Chris Jun 03 '22 at 21:02
  • Is `adv` JSON data by chance? If so, have a look at [this question an related answers](https://stackoverflow.com/questions/21104592/json-to-pandas-dataframe) – G. Anderson Jun 03 '22 at 21:06
  • The current table has year, team, offense, and defense as as columns, and the offense column contains the following: {'plays': 924, 'drives': 158, 'ppa': 0.1326638822105819, 'totalPPA': 122.58142716257767.....}. Instead, I want 'plays', 'drives', etc to be separate columns – playofthegame Jun 03 '22 at 21:34

0 Answers0