无法将json文件导入spyder



这是我第一次使用任何类型的代码。我一直在遵循一个交互式教程,我似乎被困在了第一步,试图导入一个包含足球比赛数据信息的json文件。这看起来相当简单,但一条又一条错误消息开始让我发疯。

我正试图将数据加载到python中,以便遵循教程(我将在下面留下一个链接(。我相信我已经以与教程中相同的方式保存了我的文件和数据,但当我更改文件目录并运行:import json时,我会收到一些不同的错误消息,如果有人能就我做错了什么提出建议,我将不胜感激。我的目标是加载我从GitHub下载的数据,并打开比赛JSON文件。

我也很乐意提供任何必要的信息来帮助回答这个问题。

YouTube视频:https://youtu.be/GTtu0t03FMO

错误消息:

FileNotFoundError: [Errno 2] No such file or directory: 'Statsbomb/data/competitions.json'
JSONDecodeError:Expecting value 
#Load in Statsbomb competition and match data
#This is a library for loading json files.
import json
#Load the competition file
#Got this by searching 'how do I open json in Python'
with open('Statsbomb/data/competitions.json') as f:
competitions = json.load(f)
#Womens World Cup 2019 has competition ID 72
competition_id=72
#Womens World Cup 2019 has competition ID 72
competition_id=72

#Load the list of matches for this competition
with open('Statsbomb/data/matches/'+str(competition_id)+'/30.json') as f:
matches = json.load(f)
#Look inside matches
matches[0]
matches[0]['home_team']
matches[0]['home_team']['home_team_name']
matches[0]['away_team']['away_team_name']
#Print all match results
for match in matches:
home_team_name=match['home_team']['home_team_name']
away_team_name=match['away_team']['away_team_name']
home_score=match['home_score']
away_score=match['away_score']
describe_text = 'The match between ' + home_team_name + ' and ' + away_team_name
result_text = ' finished ' + str(home_score) +  ' : ' + str(away_score)
print(describe_text + result_text)
#Now lets find a match we are interested in
home_team_required ="England"
away_team_required ="Sweden"
#Find ID for the match
for match in matches:
home_team_name=match['home_team']['home_team_name']
away_team_name=match['away_team']['away_team_name']
if (home_team_name==home_team_required) and (away_team_name==away_team_required):
match_id_required = match['match_id']
print(home_team_required + ' vs ' + away_team_required + ' has id:' + str(match_id_required))
#Exercise: 
#1, Edit the code above to print out the result list for the Mens World cup 
#2, Edit the code above to find the ID for England vs. Sweden
#3, Write new code to write out a list of just Sweden's results in the tournament.

打开('Statsbomb/data/matches/'+str(competition_id(+'/30.json'(为f:matches=json.load(f(尝试:open('Statsbomb/data/matches/'+str(competition_id(+'/3.json'(为f:matches=json.load(f(

最新更新