我对 Pandas 很陌生,所以我不知道该怎么做。我有一个带有 Pandas 的 Python 脚本,用于从在线 .csv 中检索数据,其中包含西班牙各省的 covid 数据。我想创建一个新列来创建一个新变量。这些将是(每日新增死亡人数/100.000 人口) 有可能吗?在 csv 中,我们已经有了人口数据,因此函数为:(population/1.000.000)*daily_deaths这是我的代码,所以我不知道如何开始import requestsimport pandas as pddf1 = pd.read_csv("https://raw.githubusercontent.com/montera34/escovid19data/master/data/output/covid19-provincias-spain_consolidated.csv")df1 = pd.DataFrame(df1) #no indexAlbacete = df1.loc[df1["province"] == "Albacete"]Alicante = df1[df1['ine_code'] == 3][['date',"PCR","TestAc",'province',"new_cases","activos","hospitalized","intensive_care","deceased","cases_accumulated","recovered","cases_per_cienmil","intensive_care_per_1000000","deceassed_per_100000","hospitalized_per_100000","daily_deaths","deaths_last_week"]]Almeria = df1.loc[df1['ine_code'] == 3]Alava = df1.loc[df1['ine_code'] == 1]Asturias = df1.loc[df1['ine_code'] == 33]Avila = df1.loc[df1['ine_code'] == 5]Badajoz = df1.loc[df1['ine_code'] == 6]Baleares = df1.loc[df1['ine_code'] == 7]Barcelona= df1.loc[df1['ine_code'] == 8]Bizcaia = df1.loc[df1['ine_code'] == 48]Burgos = df1.loc[df1['ine_code'] == 9]Caceres = df1.loc[df1['ine_code'] == 10]Cadiz = df1.loc[df1['ine_code'] == 11]Cantabria= df1.loc[df1['ine_code'] == 39] Castellon= df1.loc[df1['ine_code'] == 12]Ceuta = df1.loc[df1['ine_code'] == 51]Ciudad_R = df1.loc[df1['ine_code'] == 13]Cordoba = df1.loc[df1['ine_code'] == 14]Cuenca = df1.loc[df1['ine_code'] == 16]Guipuzcoa= df1.loc[df1['ine_code'] == 20]Girona = df1.loc[df1['ine_code'] == 17] Madrid = df1[df1['ine_code'] == 28][['date',"PCR","TestAc",'province',"new_cases","activos","hospitalized","intensive_care","deceased","cases_accumulated","recovered","cases_per_cienmil","intensive_care_per_1000000","deceassed_per_100000","hospitalized_per_100000","daily_deaths","deaths_last_week"]]
2 回答
慕斯王
TA贡献1864条经验 获得超2个赞
我无法轻松查看所有 DataFrame 列,但请尝试以下操作:
df1['percent_per_day'] = (df1['population']/1000000) * df1['daily_deaths']
在哪里:
df1['percent_per_day']
是你的新专栏
df1['population']
以及df1['daily_deaths']
这些列在 df1 中的名称
森林海
TA贡献2011条经验 获得超2个赞
不确定这是否是您正在寻找的内容,但根据 csv 中的列,尝试在“poblacion”为人口的情况下尝试此操作
df1['death_rate'] = (df1['poblacion']/1000000) *df1['daily_deaths']
添加回答
举报
0/150
提交
取消