I took a little different approach
# Do imports import requests, json import pandas as pd from datetime import datetime import os # Get the path of the working script path = os.path.realpath(os.path.dirname(__file__)) # The link link = 'https://fantasy.premierleague.com/api/event/36/live/' # Get response response = requests.get(link) # Covert to json format data = json.loads(response.text) # Create the column headers columns = [element for element in data['elements'][0]['stats']] # # Empty list stats = [] # Get the data for element in data['elements']: stats.append([element['stats'][key] for key in element['stats']]) # # Create the dataframe dataset = pd.DataFrame(stats, columns=columns) # # Create the filename filename = f'{path}/{datetime.today().date()}_fpl_players_weekly' # # Convert to csv dataset.to_csv(index=False, path_or_buf=filename)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags