在CSV的文本字段中有多种值
有些值是这样的 AGM00鲍德温 AGM00BOUCK公司
但是,有些是重复的,将名称改为 AGM00BOUCK01型 AGM00COBDEN01型 AGM00COBDEN02型
我的目标是为不包含数字后缀的值编写一个特定的ID
这是目前为止的代码
prov_count = 3000
prov_ID = 0
items = (name, x, y)
xy_tup = tuple(items)
if "*1" not in name and "*2" not in name:
prov_ID = prov_count + 1
else:
prov_ID = ""
看起来通配符在这里不是合适的方法,但我似乎找不到合适的解决方案。你知道吗
有不同的方法,一种是使用
isdigit
函数:使用
regex
:另一个:
以上所有方法都返回带有数字后缀的输入:
可以使用切片查找元素的最后2个字符,然后检查它是否以
'01'
或'02'
结尾:输出:
或者另一种方法是使用
str.endswith
方法:所以您的代码如下所示:
在这里使用正则表达式似乎很合适:
相关问题 更多 >
编程相关推荐