本文主要是介绍新冠疫情数据统计 蓝桥杯楼赛第二十三期(不考虑自动化处理缺省值),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原题链接
import csv
import json
import country_converter as cocodef main():cc = coco.CountryConverter()Confirmed = {"Africa": 0, "Asia": 0, "Oceania": 0,"Europe": 0, "America": 0, "Others": 0, "Total": 0}Deaths = {"Africa": 0, "Asia": 0, "Oceania": 0,"Europe": 0, "America": 0, "Others": 0, "Total": 0}Recovered = {"Africa": 0, "Asia": 0, "Oceania": 0,"Europe": 0, "America": 0, "Others": 0, "Total": 0}Active = {"Africa": 0, "Asia": 0, "Oceania": 0,"Europe": 0, "America": 0, "Others": 0, "Total": 0}country_list = []ls = []data = "楼赛第三题\okcases_country.csv"with open(data, 'r') as f:reader = csv.reader(f)for row in reader:if row[0] == "Country_Region":passelse:country_name = row[0]country_list.append(country_name)continent = cc.convert(names = country_list, to = 'continent', not_found= "Others")with open(data, 'r') as f:reader = csv.reader(f) rows = [row for row in reader]for a in range(len(continent)):#print(a)#print(int(float(rows[a+1][4])))#print(int(float(rows[a+1][5])))#print(int(float(rows[a+1][6])))#print(int(float(rows[a+1][7])))if continent[a] == "Asia":Confirmed[continent[a]] = Confirmed.get(continent[a] , 0) + int(float(rows[a+1][4]))Deaths[continent[a]] = Deaths.get(continent[a] , 0) + int(float(rows[a+1][5]))Recovered[continent[a]] = Recovered.get(continent[a] , 0) + int(float(rows[a+1][6]))Active[continent[a]] = Active.get(continent[a] , 0) + int(float(rows[a+1][7]))elif continent[a] == "Europe":Confirmed[continent[a]] = Confirmed.get(continent[a] , 0) + int(float(rows[a+1][4]))Deaths[continent[a]] = Deaths.get(continent[a] , 0) + int(float(rows[a+1][5]))Recovered[continent[a]] = Recovered.get(continent[a] , 0) + int(float(rows[a+1][6]))Active[continent[a]] = Active.get(continent[a] , 0) + int(float(rows[a+1][7]))elif continent[a] == "Africa":Confirmed[continent[a]] = Confirmed.get(continent[a] , 0) + int(float(rows[a+1][4]))Deaths[continent[a]] = Deaths.get(continent[a] , 0) + int(float(rows[a+1][5]))Recovered[continent[a]] = Recovered.get(continent[a] , 0) + int(float(rows[a+1][6]))Active[continent[a]] = Active.get(continent[a] , 0) + int(float(rows[a+1][7]))elif continent[a] == "America":Confirmed[continent[a]] = Confirmed.get(continent[a] , 0) + int(float(rows[a+1][4]))Deaths[continent[a]] = Deaths.get(continent[a] , 0) + int(float(rows[a+1][5]))Recovered[continent[a]] = Recovered.get(continent[a] , 0) + int(float(rows[a+1][6]))Active[continent[a]] = Active.get(continent[a] , 0) + int(float(rows[a+1][7]))elif continent[a] == "Oceania":Confirmed[continent[a]] = Confirmed.get(continent[a] , 0) + int(float(rows[a+1][4]))Deaths[continent[a]] = Deaths.get(continent[a] , 0) + int(float(rows[a+1][5]))Recovered[continent[a]] = Recovered.get(continent[a] , 0) + int(float(rows[a+1][6]))Active[continent[a]] = Active.get(continent[a] , 0) + int(float(rows[a+1][7]))elif continent[a] == "Others":Confirmed[continent[a]] = Confirmed.get(continent[a] , 0) + int(float(rows[a+1][4]))Deaths[continent[a]] = Deaths.get(continent[a] , 0) + int(float(rows[a+1][5]))Recovered[continent[a]] = Recovered.get(continent[a] , 0) + int(float(rows[a+1][6]))Active[continent[a]] = Active.get(continent[a] , 0) + int(float(rows[a+1][7]))Confirmed["Total"] = Confirmed["Africa"] + Confirmed["Asia"] + Confirmed["Oceania"] + Confirmed["Europe"] + Confirmed["America"] +Confirmed["Others"]Active["Total"] = Active["Africa"] + Active["Asia"] + Active["Oceania"] + Active["Europe"] + Active["America"] +Active["Others"]Deaths["Total"] = Deaths["Africa"] + Deaths["Asia"] + Deaths["Oceania"] + Deaths["Europe"] + Deaths["America"] +Deaths["Others"]Recovered["Total"] = Recovered["Africa"] + Recovered["Asia"] + Recovered["Oceania"] + Recovered["Europe"] + Recovered["America"] +Recovered["Others"]results = {"Confirmed": Confirmed,"Deaths": Deaths,"Recovered": Recovered,"Active": Active,}print(results) return json.dumps(results, indent=2)
main()
#一个学生物的编程爱好者#
这是在不考虑自动化处理缺省值的情况下的答案,至于使用numpy和pandas的自动化处理的版本近期将会更新。
这篇关于新冠疫情数据统计 蓝桥杯楼赛第二十三期(不考虑自动化处理缺省值)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!