How to export data into excel (for-loop if clause)

Hello all,
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:
Premier League Man Utd - Arsenal 2:1

I want to have this output in excel file in this format
Premier League,Man Utd - Arsenal,2:1

Use string formatting:

print('{},{},{}'.format(b["league"], b["teams"], b["score"][0]))

I’d also suggest using better variable names for clarity.

1 Like

thank you for response matthew.
i’m sorry for late reply.
i was dealing with my health problems.
i ll take your suggestion into account.
thank you.