简体   繁体   English

Pandas: AttributeError: 'str' object 没有属性 'isnull'

[英]Pandas: AttributeError: 'str' object has no attribute 'isnull'

I'm creating a new column named lead_actor_actress_known whose values is boolean based on whether there value in 2nd column lead_actor_actress has value or not.我正在创建一个名为lead_actor_actress_known的新列,其值为boolean,具体取决于第二列lead_actor_actress中是否有值。 If there is a value(Name of actors) populate 1st column using True if there is no value, return False如果有值(演员名称),则使用True填充第一列,如果没有值,则返回False

AttributeError: 'str' object has no attribute 'isnull' AttributeError: 'str' object 没有属性 'isnull'

My code is throwing an error above.我的代码在上面抛出错误。

df['lead_actor_actress_known'] = df['lead_actor_actress'].apply(lambda x: True if x.isnull() else False)

What i'm i missing?我错过了什么?

Henry Ecker's comment contains the answer to this question, I am reproducing in the answer section for convenience.亨利埃克的评论包含这个问题的答案,为方便起见,我在答案部分复制。 Replace your application of the .apply() method with the code df['lead_actor_actress_known'] = df['lead_actor_actress'].isna() ..apply()方法的应用程序替换为代码df['lead_actor_actress_known'] = df['lead_actor_actress'].isna()

The thing to know here is that df['lead_actor_actress'].isna() returns a "Boolean mask" (a series of True and False values) and this is exactly what you are asking to assign the variable lead_actor_actress .这里要知道的是df['lead_actor_actress'].isna()返回一个“布尔掩码”(一系列 True 和 False 值),这正是您要求分配变量lead_actor_actress的内容。

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

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