从列pandas中只获取纯非数字元素

问题描述 投票:0回答:2

我有一个这样的数据列:

   Phrase

   A4678LM
   AFNH
   2l6m8
   2312435
   122
   ABC
   HOW
   IS
   Pa805

等等。现在这是python中数据框中的一列。我想只选择纯非数字值,例如:

  Phrase

   AFNH
   ABC
   HOW
   IS

该列仅包含纯非数字值。我的熊猫专栏的类型是

短语:对象类型

我尝试使用这个公式:

df.applymap(np.isreal) 

但我无法得到结果。我显示所有都是假的。如何才能获得纯粹的非数字值?

python regex pandas dataframe data-manipulation
2个回答
1
投票

您可以尝试以下代码:

df[df['Phrase'].str.match("^[a-zA-Z]+$")]

它只检查每一行的字母,如果它包含,则选择它。


1
投票

使用str.contains

df[~df.Phrase.str.contains('\d+')]
Out[780]: 
  Phrase
1   AFNH
5    ABC
6    HOW
7     IS
© www.soinside.com 2019 - 2024. All rights reserved.