简体   繁体   English

Python:df['a']str.contains() 可以有多个条件吗?

[英]Python:Can df['a']str.contains() have multiple condition?

I have 4 types of value in my df column A example shown below我的 df 列中有 4 种类型的值如下所示的示例

123
123/123/123/123/123
123,,123,,123
1234-1234-1234

i want index of those value which do not have any type of sepertor in it我想要那些没有任何类型分隔符的值的索引

I tried like this but failed to get results我试过这样但没有得到结果

mask = df["A"].str.contains(',','/' na=False)

Any help would be appreciated任何帮助,将不胜感激

If possible invert logic - get all rows if only numbers without any separator use ^\d+$ - ^ means start of string, \d+ means one or more digits and $ means end of string - together only numbers values:如果可能,反转逻辑 - 如果仅使用没有任何分隔符的数字,则获取所有行^\d+$ - ^表示字符串的开头, \d+表示一位或多位数字, $表示字符串的结尾 - 一起只有数字值:

mask = df["A"].str.contains('^\d+$', na=False)

print (mask)
0     True
1    False
2    False
3    False
Name: A, dtype: bool

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

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