我需要制作直方图并在地图上显示统计数据。我选择了NBA统计数据(平均速度和拥有该速度的球员数量)。
此处是我的代码:
import json
dico = {}
with open("speedata.json") as file:
data = json.load(file)
for player in data["resultSets"][0]["rowSet"]:
dico[player[1]] = player
for playerName, playerStats in dico.items():
print("{%s, %s} -> Average Speed: %s" % (playerName,playerStats[4], playerStats[8]))
我打印的是例如:
{DeMar DeRozan, TOR} -> Average Speed: 4.1
{Brandon Knight, MIL} -> Average Speed: 4.2
{Brandon Rush, UTA} -> Average Speed: 4.2
{JJ Redick, LAC} -> Average Speed: 4.6
{Jeremy Tyler, NYK} -> Average Speed: 4.0
{John Salmons, SAC} -> Average Speed: 4.0
{Luke Babbitt, NOP} -> Average Speed: 4.3
{DeAndre Liggins, MIA} -> Average Speed: 3.4
{Chris Kaman, LAL} -> Average Speed: 4.2
{Robert Covington, HOU} -> Average Speed: 4.2
{Dorell Wright, POR} -> Average Speed: 4.2
{Darius Miller, NOP} -> Average Speed: 4.0
我希望获得x平均速度的玩家数量,然后根据他们的团队对其进行排序。
我的老师告诉我将dico(这是一本字典)的一些信息输入到列表中;但我真的看不出用途。
任何提示? (这是作业)