[英]How do I find lowercase words in a DataFrame column that has NaNs?
我有一个 dataframe 列,其中一列中有这些值:
Jerry
NaN
bill
Sol
我想捕捉所有小写名称,即bill
。 但是我的代码一直卡在NaN
上。
这是我的代码:
for n in df_copy.name:
if n.islower():
print(n)
我收到此错误:
---------------------------------------------------------------------------
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'
所以我尝试将值设为字符串:
for n in df_copy.name:
if n.str.islower():
print(n)
它给了我这个错误:
---------------------------------------------------------------------------
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
啊。 有谁知道如何解决这个问题?
我们可以使用str.islower
df[df.name.str.islower().fillna(False)]
Out[243]:
name
2 bill
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.