给定如下数据帧,我需要检查room
列:
id room
0 1 A-102
1 2 201
2 3 B309
3 4 C·102
4 5 E_1089
此列的正确格式应为numbers
、alphabet
或hyphen
,否则,用incorrect
填充check
列
预期结果如下:
id room check
0 1 A-102 NaN
1 2 201 NaN
2 3 B309 NaN
3 4 C·102 incorrect
4 5 E_1089 incorrect
这里的非正式语法可以是:
df.loc[<filter1> | (<filter2>) | (<filter3>), 'check'] = 'incorrect'
提前谢谢你的帮助
使用
str.match
强制所有字符:或
str.contains
带否定模式:输出:
如果要更新现有的
check
列,请使用loc
访问。例如:相关问题 更多 >
编程相关推荐