Dataframe 返回数据帧的副本,该数据帧中仅包含缺少数据的行

Dataframe 返回数据帧的副本,该数据帧中仅包含缺少数据的行,dataframe,julia,Dataframe,Julia,我正在寻找DataFrames.jl中的dropmissing函数的反面,以便用户知道在哪里可以修复他们的坏数据。看起来这应该很容易,但是filter函数需要指定一个列,而我无法让它遍历所有列 julia> df=DataFrame(a=[1, missing, 3], b=[4, 5, missing]) 3×2 DataFrame │ Row │ a │ b │ │ │ Int64? │ Int64? │ ├─────┼─────────┼─────

我正在寻找DataFrames.jl中的
dropmissing
函数的反面,以便用户知道在哪里可以修复他们的坏数据。看起来这应该很容易,但是
filter
函数需要指定一个列,而我无法让它遍历所有列

julia> df=DataFrame(a=[1, missing, 3], b=[4, 5, missing])
3×2 DataFrame
│ Row │ a       │ b       │
│     │ Int64?  │ Int64?  │
├─────┼─────────┼─────────┤
│ 1   │ 1       │ 4       │
│ 2   │ missing │ 5       │
│ 3   │ 3       │ missing │

julia> filter(x -> ismissing(eachcol(x)), df)
ERROR: MethodError: no method matching eachcol(::DataFrameRow{DataFrame,DataFrames.Index})

julia> filter(x -> ismissing.(x), df)
ERROR: ArgumentError: broadcasting over `DataFrameRow`s is reserved

我基本上是在尝试重新创建
disallowmissing
函数,但有一条更有用的错误消息。

这里有两种方法:

julia> df = DataFrame(a=[1, missing, 3], b=[4, 5, missing])
3×2 DataFrame
│ Row │ a       │ b       │
│     │ Int64?  │ Int64?  │
├─────┼─────────┼─────────┤
│ 1   │ 1       │ 4       │
│ 2   │ missing │ 5       │
│ 3   │ 3       │ missing │

julia> df[.!completecases(df), :] # this will be faster
2×2 DataFrame
│ Row │ a       │ b       │
│     │ Int64?  │ Int64?  │
├─────┼─────────┼─────────┤
│ 1   │ missing │ 5       │
│ 2   │ 3       │ missing │

julia> @view df[.!completecases(df), :]
2×2 SubDataFrame
│ Row │ a       │ b       │
│     │ Int64?  │ Int64?  │
├─────┼─────────┼─────────┤
│ 1   │ missing │ 5       │
│ 2   │ 3       │ missing │

julia> filter(row -> any(ismissing, row), df)
2×2 DataFrame
│ Row │ a       │ b       │
│     │ Int64?  │ Int64?  │
├─────┼─────────┼─────────┤
│ 1   │ missing │ 5       │
│ 2   │ 3       │ missing │

julia> filter(row -> any(ismissing, row), df, view=true) # requires DataFrames.jl 0.22
2×2 SubDataFrame
 Row │ a        b
     │ Int64?   Int64?
─────┼──────────────────
   1 │ missing        5
   2 │       3  missing

如果我不需要副本,有没有更快的方法?我意识到我可能只能查看原始数据帧的一部分,因为我无论如何都会出错。对于下周发布的版本中的
filter
pass
view=true
kwarg(您也可以安全地使用master;唯一阻碍发布的是一些小的打印调整)。对于
completecases
解决方案,只需将
@view
放在整个表达式前面。