Python 是否从数据框中选择包含整数但不包含字母的行?
原始数据帧(df): 选择后的预期数据帧(df):Python 是否从数据框中选择包含整数但不包含字母的行?,python,pandas,dataframe,Python,Pandas,Dataframe,原始数据帧(df): 选择后的预期数据帧(df): A B 0 1 green 3 4.3.4 yellow 4 0# black 5 0.3 white 列的类型为字符串 我不知道如何使用regex/str.contains()获得结果 您可以使用字符类[a-zA-Z]匹配字母,并使用~反向选择 df[~df['A'].str.contains('[a-zA-Z]')] Out: A B 0
A B
0 1 green
3 4.3.4 yellow
4 0# black
5 0.3 white
列的类型为字符串
我不知道如何使用regex/
str.contains()
获得结果 您可以使用字符类[a-zA-Z]
匹配字母,并使用~
反向选择
df[~df['A'].str.contains('[a-zA-Z]')]
Out:
A B
0 1 green
3 4.3.4 yellow
4 0# black
5 0.3 white
您可以使用字符类
[a-zA-Z]
匹配字母,并使用~
反转选择
df[~df['A'].str.contains('[a-zA-Z]')]
Out:
A B
0 1 green
3 4.3.4 yellow
4 0# black
5 0.3 white