对nba数据,统计不同的大学各队下面,人员的总人数,工资总和
时间: 2024-05-12 07:19:41 浏览: 100
很抱歉,作为AI语言模型,我无法直接访问和处理实时的NBA数据。但是,以下是一个可能的Python代码示例,根据假设的数据来统计不同大学的球队中的总人数和总工资。
假设有以下数据:
```python
nba_data = [
{'name': 'LeBron James', 'university': 'None', 'team': 'Los Angeles Lakers', 'salary': 37436858},
{'name': 'Stephen Curry', 'university': 'Davidson', 'team': 'Golden State Warriors', 'salary': 43006362},
{'name': 'Kevin Durant', 'university': 'Texas', 'team': 'Brooklyn Nets', 'salary': 40000000},
{'name': 'Kawhi Leonard', 'university': 'San Diego State', 'team': 'Los Angeles Clippers', 'salary': 32742000},
{'name': 'James Harden', 'university': 'Arizona State', 'team': 'Brooklyn Nets', 'salary': 40824000},
{'name': 'Anthony Davis', 'university': 'Kentucky', 'team': 'Los Angeles Lakers', 'salary': 32742000},
{'name': 'Russell Westbrook', 'university': 'UCLA', 'team': 'Washington Wizards', 'salary': 44211146},
{'name': 'Damian Lillard', 'university': 'Weber State', 'team': 'Portland Trail Blazers', 'salary': 43869000},
{'name': 'Joel Embiid', 'university': 'Kansas', 'team': 'Philadelphia 76ers', 'salary': 29542010},
{'name': 'Ben Simmons', 'university': 'LSU', 'team': 'Philadelphia 76ers', 'salary': 17720000},
{'name': 'DeMar DeRozan', 'university': 'USC', 'team': 'San Antonio Spurs', 'salary': 27739975},
{'name': 'Devin Booker', 'university': 'Kentucky', 'team': 'Phoenix Suns', 'salary': 29434475},
{'name': 'Ja Morant', 'university': 'Murray State', 'team': 'Memphis Grizzlies', 'salary': 9258000},
{'name': 'Zion Williamson', 'university': 'Duke', 'team': 'New Orleans Pelicans', 'salary': 10245480},
{'name': 'RJ Barrett', 'university': 'Duke', 'team': 'New York Knicks', 'salary': 8239200},
{'name': 'LaMelo Ball', 'university': 'None', 'team': 'Charlotte Hornets', 'salary': 8199600}
]
```
则以下Python代码可以计算每个大学的总人数和总薪资:
```python
from collections import defaultdict
# 创建一个字典,用于按大学名称存储球员信息
university_data = defaultdict(list)
# 将球员按大学名称存储
for player in nba_data:
university_data[player['university']].append(player)
# 创建一个字典,用于存储每个大学的总人数和总薪资
totals_by_university = {}
# 计算每个大学的总人数和总薪资
for university, players in university_data.items():
total_players = len(players)
total_salary = sum(player['salary'] for player in players)
totals_by_university[university] = {'total_players': total_players, 'total_salary': total_salary}
# 打印结果
for university, totals in totals_by_university.items():
print(f'{university}: {totals["total_players"]} players, ${totals["total_salary"]}')
```
输出结果应为:
```
None: 2 players, $45636458
Davidson: 1 players, $43006362
Texas: 1 players, $40000000
San Diego State: 1 players, $32742000
Arizona State: 1 players, $40824000
Kentucky: 2 players, $62176475
UCLA: 1 players, $44211146
Weber State: 1 players, $43869000
Kansas: 1 players, $29542010
LSU: 1 players, $17720000
USC: 1 players, $27739975
Murray State: 1 players, $9258000
Duke: 2 players, $18484680
```
阅读全文