简体   繁体   English

Python 字符串('$' 后跟字符而不是数字)

[英]Python string ('$' followed by characters rather than numbers)

May I ask if I just want to filter all the string of "$" followed by characters but not those followed by numbers, what python codes should I modify based on the following codes I have?请问如果我只是想过滤所有“$”后跟字符的字符串而不是那些后跟数字的字符串,我应该根据我拥有的以下代码修改哪些python代码? Thanks.谢谢。

def color_negative_red(value):
    if '$' in value:
        color = 'red'
 
    else:
        color = 'black'

    return 'color: %s' % color

Dataframe = Dataframe.style.applymap(color_negative_red, subset=['column_1'])

You could use regex and specifically a lookahead assertion:您可以使用正则表达式,特别是前瞻断言:

import re

if re.search(r'\$(?=[A-Za-z]+)', value):
    color = 'red'

This will find any letter character following a $ except digits.这将找到$后面的任何字母字符,但数字除外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM