我想我遇到了一个初学者的问题: ->我想遍历一个数组,然后将值插入执行的代码行中。 对于下面的尝试,我得到“ SyntaxError:无法分配给运算符”
#Country-subsets (all countries in dataframe)
for s in country_filter:
s.lower() + '_immu_edu' = immu_edu.loc[immu_edu['CountryName'] == s]
感谢您的帮助!
我的预期输出是:
guinea_immu_edu = immu_edu.loc[immu_edu['CountryName'] == "Guinea"]
lao_immu_edu = immu_edu.loc[immu_edu['CountryName'] == "Lao PDR"]
bf_immu_edu = immu_edu.loc[immu_edu['CountryName'] == "Burkina Faso"]
us_immu_edu = immu_edu.loc[immu_edu['CountryName'] == "United States"]
ge_immu_edu = immu_edu.loc[immu_edu['CountryName'] == "Germany"]
答案 0 :(得分:0)
将值存储在字典中,并使用以下键进行访问:
my_dict = dict()
for s in country_filter:
my_dict[s.lower() + '_immu_edu'] = immu_edu.loc[immu_edu['CountryName'] == s]