Files
simulated-examination/data_analysis.py
2026-06-23 11:12:36 +08:00

26 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
read_file = open("movies.json", "r", encoding="utf-8")
movie_data = json.load(read_file)
read_file.close()
rank_movie = sorted(movie_data, key=lambda x: x["rating"])
min_score_movie = rank_movie[0]
max_score_movie = rank_movie[-1]
print("1、评分最低电影", min_score_movie["title"], ",评分:", min_score_movie["rating"])
print(" 评分最高电影:", max_score_movie["title"], ",评分:", max_score_movie["rating"])
genre_count_dict = {}
for film in movie_data:
film_type = film["genre"]
if film_type in genre_count_dict:
genre_count_dict[film_type] = genre_count_dict[film_type] + 1
else:
genre_count_dict[film_type] = 1
print("\n2、各类型电影统计", genre_count_dict)
director_count_dict = {}
for film in movie_data:
dir_name = film["director"]
if dir_name in director_count_dict:
director_count_dict[dir_name] += 1
else:
director_count_dict[dir_name] = 1
print("\n3、各导演电影数量", director_count_dict)
count_after_2020 = 0