I am utilizing the API here: https://github.com/CFBD/cfbd-python/blob/master/docs/GamesApi.md#get_games that returns a list of dictionaries and want to get the data into a format that I can manipulate or store it into a database. I have attempted to convert it to a pandas dataframe with the pd.DataFrame() method as outlined in this question: Convert list of dictionaries to a pandas DataFrame. I first have stored the API response as a variable api_response = api_instance.get_games()
, then converted it to a DataFrame with df = pd.DataFrame(api_response)
. Printing that DataFrame returns only one column containing the entire dictionary for each game instance instead of splitting out columns by key and populating with values.
And example of how the data is returned for two games from print(api_response)
is in the following format:
[{'attendance': None,
'away_conference': 'FBS Independents',
'away_id': 87,
'away_line_scores': [7, 10, 21, 0, 3],
'away_points': 41,
'away_post_win_prob': 0.44707054087049625,
'away_team': 'Notre Dame',
'conference_game': True,
'excitement_index': 7.4132284343,
'highlights': None,
'home_conference': 'ACC',
'home_id': 52,
'home_line_scores': [7, 7, 6, 18, 0],
'home_points': 38,
'home_post_win_prob': 0.5529294591295038,
'home_team': 'Florida State',
'id': 401282614,
'neutral_site': False,
'notes': None,
'season': 2021,
'season_type': 'regular',
'start_date': '2021-09-05T23:30:00.000Z',
'start_time_tbd': False,
'venue': 'Bobby Bowden Field at Doak Campbell Stadium',
'venue_id': 3697,
'week': 1}, {'attendance': None,
'away_conference': 'ACC',
'away_id': 97,
'away_line_scores': [0, 0, 10, 14],
'away_points': 24,
'away_post_win_prob': 0.04096564974450303,
'away_team': 'Louisville',
'conference_game': False,
'excitement_index': 4.6236823229,
'highlights': None,
'home_conference': 'SEC',
'home_id': 145,
'home_line_scores': [9, 17, 3, 14],
'home_points': 43,
'home_post_win_prob': 0.959034350255497,
'home_team': 'Ole Miss',
'id': 401282055,
'neutral_site': True,
'notes': None,
'season': 2021,
'season_type': 'regular',
'start_date': '2021-09-07T00:00:00.000Z',
'start_time_tbd': False,
'venue': 'Mercedes-Benz Stadium',
'venue_id': 5348,
'week': 1}]
Is there a better way to store this that I am overlooking?