[英]Update 1st column based on string present in 2nd column
DF["Price"]=np.where(DF["Special Offer"].str.contains(r"(BUY 1)(GET1)(50%)",case=False,regex=True),DF["Price]*2,DF["Price])
You forgot the spaces in between, and also dont group with brackets.你忘记了中间的空格,也不用括号分组。 As I undestand you want to capture the price.
正如我不明白的那样,您想获取价格。 So we capture it with \\d+ and check if there are needed context with a lookahead like (?= \\| BUY 1 GET 1 50%)
所以我们用 \\d+ 捕获它并检查是否有需要的上下文,例如 (?= \\| BUY 1 GET 1 50%)
\d+(?= ?\| ?BUY 1[, ] ?GET 1(?:,? ?| at )50%)
\d+(?= ?\| ?BUY 1[, ] ?GET 1(?:, ?| at )40%)
demo演示
https://regex101.com/r/vG1kzW/3 https://regex101.com/r/vG1kzW/3
https://regex101.com/r/QImMZf/2 https://regex101.com/r/QImMZf/2
this one is working.这个正在工作。
\d+(?= ?\| ?BUY 1[, ] ?GET 1(?:,? ?| at )50%)
\d+(?= ?\| ?BUY 1[, ] ?GET 1(?:, ?| at )40%)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.