[英]How to check for a digit with a specific caracter like 10g in python
您没有正确使用正则表达式,您实际上是在检查字符串 '\d+\s*g' 是否出现在成分列表中。
import re
exp = re.compile(r".*\d+\s*g.*")
df['ingredients_text'].apply(lambda x: [s for s in x if (re.match(exp, s) or ('%' in s))])
表达式r".*\d+\s*g.*"
将匹配以下任何内容:
有关如何使用正则表达式的更多信息,请参见此处: https://docs.python.org/3/library/re.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.