for i in test.construction:
if i.find("Wood"):
test["Category"]="tree"
print (test[["construction", "Category"]])
输出: 建筑类别
Masonry tree
Masonry tree
Wood tree
Wood tree
我使用find而不是'==',因为它可能在构造列中包含多个单词/字符串。 每次都是“树”。 我想要Category=“Mason”当construction=“Masonry”
谢谢你的帮助
似乎您需要^{} ,条件由^{} 创建,如果需要
tree
,如果条件失败mason
:或者,如果有许多条件,请使用带有in的自定义函数作为测试子字符串:
相关问题 更多 >
编程相关推荐