【发布时间】:2017-08-22 16:35:10
【问题描述】:
我想使用np.where,但需要使用通配符匹配字符串。这可能吗,或者在这种情况下最好使用其他功能吗?
df['PRODUCT'] = np.where(df['TYPE'] == '2b', 'Pencil',
np.where(df['TYPE'] like 'I5%', 'Ruler', 0))
我尝试使用 in 运算符,但这不起作用。
df['PRODUCT'] = np.where(df['TYPE'] == '2b', 'Pencil',
np.where('I5' in df['TYPE'], 'Ruler', 0))
【问题讨论】:
标签: python python-2.7 pandas numpy