【发布时间】:2021-12-21 15:30:44
【问题描述】:
df2 = np.where(df2['color'] != 'blue' | 'red')
我想为多个分类值创建一个类别,例如:
如果颜色不是蓝色或红色,则将颜色称为“其他”
谢谢
【问题讨论】:
-
df['color'] = np.where(df['color'].isin(['blue', 'red']), df['color'], 'Other')as jezrael recommends
标签: python pandas conditional-statements rename