Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loops and Child Attributes
#3
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


Reply


Messages In This Thread
Loops and Child Attributes - by antweeman82 - May-10-2024, 03:48 PM
RE: Loops and Child Attributes - by deanhystad - May-10-2024, 06:07 PM
RE: Loops and Child Attributes - by menator01 - May-10-2024, 06:25 PM
RE: Loops and Child Attributes - by antweeman82 - May-13-2024, 11:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using one child class method in another child class garynewport 5 1,857 Jan-11-2023, 06:07 PM
Last Post: garynewport
  XML Parsing Child karthi_python 1 1,990 May-16-2019, 01:37 PM
Last Post: karthi_python
  parent/add and child/div PyMan 1 2,543 Feb-23-2018, 04:38 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020