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
football.py:
output:
I want to export json data file into excel in terms of loop code I wrote in the below.
football.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
{ "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" ] } ] } ] } ] } |
1 2 3 4 5 6 7 8 9 10 |
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: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.