1 回答
TA贡献1886条经验 获得超2个赞
要country_name创建列表,而不是使用连接值的元素列表:
dfn["country_name"] = dfn["country_code"].apply(lambda x: [masked[i] for i in x.split(", ")])
然后你的第二个解决方案运行良好:
american = ["United States", "Brazil"]
dfn["all_but_american1"] = dfn["country_name"].apply(lambda x: [i for i in x if i not in american])
print (dfn)
country_code all_but_american_desired \
0 USA, UK, FRA [United Kingdom, France]
1 RUS, ZHC, JAP [Russia, China, Japan]
2 IN, BRA, ES [India, Spain]
country_name all_but_american1
0 [United States, United Kingdom, France] [United Kingdom, France]
1 [Russia, China, Japan] [Russia, China, Japan]
2 [India, Brazil, Spain] [India, Spain]
添加回答
举报