简体   繁体   English

从pandas数据框中选择包括整数但没有字母的行?

[英]Select rows including integer but no letter from pandas dataframe?

Raw dataframe (df): 原始数据帧(df):

     A       B
0    1      green
1    2s     red
2    s      blue
3    4.3.4  yellow
4    0#     black
5    0.3    white 

Expected dataframe (df) after selecting: 选择后的预期数据帧(df):

     A       B
0    1      green
3    4.3.4  yellow
4    0#     black
5    0.3    white 

The type of column A is string. 列A的类型是字符串。

I have no idea how to use regex/ str.contains() to get the result. 我不知道如何使用regex / str.contains()获得结果。

You can use a character class [a-zA-Z] to match the letters and inverse the selection with ~ . 您可以使用字符类[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

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

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