Aug-31-2022, 01:46 PM
Hello all,
I want to export json data file into excel in terms of loop code I wrote in the below.
football.json
I want to export json data file into excel in terms of loop code I wrote in the below.
football.json
{ "results": [ { "leagues": [ { "matches": [ { "league": "Premier League", "teams": "Liverpool - Chelsea", "score": [ "3:0" ] }, { "league": "Premier League", "teams": "Man Utd - Arsenal", "score": [ "2:1" ] } ] }, { "matches": [ { "league": "La Liga", "teams": "Atletico Madrid - Villareal", "score": [ "0:2" ] } ] } ] } ] }football.py:
import json with open("football.json") as f: jsondata = json.load(f) for a in jsondata["results"][0]["leagues"]: for b in a["matches"]: if "Liverpool" in b["teams"] or "La Liga" in b["league"]: continue print(b["league"],b["teams"],b["score"][0])output:
Output:Premier League Man Utd - Arsenal 2:1
I want to have this output in excel file in this formatOutput:Premier League,Man Utd - Arsenal,2:1
Thanks all for your interest.