简体   繁体   中英

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:

Jerry
NaN
bill
Sol

I want to catch the all lowercase names, ie, bill . But my code keeps getting stuck, I think on the 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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