python读取网址CSV文件并统计结果
首先第一步打开pycharm(bushi)
import pandas as pd
data = pd.read_csv(r"http://data.ontario.ca/dataset/f4112442-bdc8-45d2-be3c-12efae72fb27/resource/455fd63b-603d-4608-8216-7d8647f43350/download/conposcovidloc.csv")
print("Please input your city:for example (Toronto):")
entry = input()
city=data[data['Reporting_PHU_City'].isin([entry])]
sum=len(city)
FEMALE = city['Client_Gender'].isin(['FEMALE']).sum()
MALE = city['Client_Gender'].isin(['MALE']).sum()
Fifty = city['Age_Group'].isin(['50s']).sum()
Sixty = city['Age_Group'].isin(['60s']).sum()
Seventy = city['Age_Group'].isin(['70s']).sum()
print("\nTotal {0} Cases Count:{1};\n"
"FEMALE:{2} MALE:{3}\nAge Group\n"
"50s :{4} \n60s :{5} \n70s :{6} \n".format(entry,sum,FEMALE,MALE,Fifty,Sixty,Seventy))
输出结果
|