![](/img/trans.png)
[英]How to split a string in Python until one of specific characters occurs from right to left?
[英]Find a specific symbol in a string and remove a number of characters to the left of it and to the right in python
我有一个带有如下字符串的熊猫列:
"[{'node': {'text': '2900₸ размері: 2-3-4-5-6..."
“[{'node': {'text': '3000₸размері: 1-2-3-4...”
我想删除“₸”符号左侧的所有内容,除了保留价格,即 2900₸(也可能是 5 位数字); 然后删除“₸”符号右侧的所有内容。 ₸的Unicode是这样的:U+20B8
定义一个 function 来获取价格(需要import regex
)
def get_price(s):
match = re.search("^.+'(\d+₸).*", s)
if match != None:
return match.group(1)
else:
print('No match:', s)
现在映射上述内容: df['price'] = df['old_price'].map(get_price)
其中'old_price'是要减少的数据的列名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.