- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想在数据框的多个列上使用 .notnull()
来消除包含“NaN”值的行。
假设我有以下 df
:
A B C
0 1 1 1
1 1 NaN 1
2 1 NaN NaN
3 NaN 1 1
我尝试使用此语法但它不起作用?你知道我做错了什么吗?
df[[df.A.notnull()],[df.B.notnull()],[df.C.notnull()]]
我得到这个错误:
TypeError: 'Series' objects are mutable, thus they cannot be hashed
我应该怎么做才能获得以下输出?
A B C
0 1 1 1
有什么想法吗?
最佳答案
您可以先通过 df[['A','B','C']]
选择列的子集,然后应用 notnull
并指定是否 all
掩码中的值为 True
:
print (df[['A','B','C']].notnull())
A B C
0 True True True
1 True False True
2 True False False
3 False True True
print (df[['A','B','C']].notnull().all(1))
0 True
1 False
2 False
3 False
dtype: bool
print (df[df[['A','B','C']].notnull().all(1)])
A B C
0 1.0 1.0 1.0
print (df.dropna(subset=['A', 'B', 'C']))
A B C
0 1.0 1.0 1.0
什么是相同的:
print (df.dropna(subset=['A', 'B', 'C'], how='any'))
意味着删除所有行,其中至少有一个 NaN
值。
关于python - 在 Pandas 中使用 .notnull() 时正确的语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38702332/
我开始在 Intellij-14 下组装一个小应用程序。它在那里编译并运行。当我更新到 15 时,我开始收到所有类的 NotNull Instrumentation 错误。错误消息只是指出该类失败了—
我应该使用这些注解中的哪一个? INTELLIJ 引入了自己的带有注释的库。我读到用这些注释标记方法参数和类属性是很好的实践,但我想知道它们做了什么。有很多带有注解的库(spring 也有像 Null
我对一个相当笨拙的标题表示歉意,我刚刚从我的具体问题中得到了更通用的问题,我认为这是问题的核心。简单地说,我有一个数据框和一个长度与列数或行数相同的列表。我想用列表中的相应值替换数据框中的 notnu
我正在学习Java注释,我想设计一个像@NotNull这样的注释,它强制编译器在以下情况下抛出错误: @NotNull private String myVar = null; 现在,我对在注释正文中
我在 POJO 之一中使用 javax.validation.constraints.NotNull,如下所示: public class Abc { @NotNull private final S
我稍微更改了 Adam D Ruppes 模块 notnull.d 以仅允许将 NotNull 继承的类实例分配给 NotNull使用构造函数的基类实例 /** Assignment from $(D
我有一个使用 Spring Data for Couchbase 的 springBoot 2.1.9.RELEASE 应用程序 我有这个对象 @Data @AllArgsConstructor @N
我正在使用 netcoreapp3.0 和 Visual Studio 16.3.1 并有一个简单的类。 ReSharper 2019.2.20190828.152259 也已安装。 这里是cspro
public class EventBus { [NotNull] // annotation not valid on this declaration type private s
我有一个实体: @Entity public class MyEntity { @Id private String Id; @NotNull @Column(nullable = f
我最近决定开始使用空校验和注释 (@NotNull),我使用 Intellij Idea's annotations library访问这些。我试图弄清楚这些注释是否会在运行时工作以检查值是否为空,如
我有这样的方法: public String getParamValue(@NotNull String param) { ....... .......
我不知道如何使用@NotNull。我写了@NotNull,但我无法在Tomcat 中获取消息或错误消息。 我使用了@NotEmpty。但这会导致 Tomcat 崩溃。 @NotNull @Co
我有一个简单的方法来获取给定 companyId 的文档列表。方法如下: @Override public List getDocumentList(@NotNull Integer companyI
根据 hibernate validator 引用文档 - 11.1.1 节。数据库模式级验证 ( https://docs.jboss.org/hibernate/stable/validator/
以下代码没有抛出任何错误,它是一个独立的 java 程序。相反,如果我传递 null,它将在控制台中打印 null。请帮助我,如何启用@notnull 注释。 import javax.validat
我正在查看 asp.net vnext engineering guideline并注意到他们建议使用 NotNull 属性,而不是显式检查输入参数是否为 null 并抛出 ArgumentNullE
@NotEmpty,@NotNull和@NotBlank的区别 @NotEmpty :不能为null,且Size>0 @NotNull:不能为null,但可以为empty,没有Size的约束 @Not
我的应用程序包含联赛、球员和球队。该应用程序允许客户创建一个联盟,其中包括球队和这些球队的球员。 稍后,客户端可以通过添加带有球员的新球队来修改联赛。正是在这一点上,客户端从我的应用程序中收到了意外的
我在某些字段上有 @NotNull 注释。但是,当我尝试生成 diffChangelog 时,它会删除所有非空约束 sample 类: public class User { @NotNull
我是一名优秀的程序员,十分优秀!