简体   繁体   English

如何在具有 NaN 的 DataFrame 列中查找小写单词?

[英]How do I find lowercase words in a DataFrame column that has NaNs?

I have a dataframe column that has these values in one of its columns:我有一个 dataframe 列,其中一列中有这些值:

Jerry
NaN
bill
Sol

I want to catch the all lowercase names, ie, bill .我想捕捉所有小写名称,即bill But my code keeps getting stuck, I think on the NaN .但是我的代码一直卡在NaN上。

Here is my code:这是我的代码:

for n in df_copy.name:
    if n.islower():
        print(n) 

I get this error:我收到此错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-296-2e5fe579149d> in <module>
      1 for n in df_copy.name:
----> 2     if n.islower():
      3         print(n)

AttributeError: 'float' object has no attribute 'islower'

So I tried making the values a string:所以我尝试将值设为字符串:

for n in df_copy.name:
    if n.str.islower():
        print(n)

It gives me this error:它给了我这个错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-295-7e9d8aa5abad> in <module>
      1 for n in df_copy.name:
----> 2     if n.str.islower():
      3         print(n)

AttributeError: 'str' object has no attribute 'str

Argh.啊。 Does anyone know how to solve this?有谁知道如何解决这个问题?

We can using str.islower我们可以使用str.islower

df[df.name.str.islower().fillna(False)]
Out[243]: 
   name
2  bill

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

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