Skip to content

Add replace!(::AbstractDataFrame, cols, ...) methodย #2257

Open
@CameronBieganek

Description

@CameronBieganek

The manual shows how to replace values in multiple columns, e.g.

df2 = ifelse.(df .== 999, missing, df)

That's a neat trick, but it would be convenient if we had replace and replace! methods for data frames. Something like the following:

df2 = replace(df, :, 999 => missing)

df3 = replace(df, Between(:a, :c), 999 => missing)

Of course the eltype conversion behavior would mirror the behavior for Base.replace:

julia> y = [2, 5, 999, 7];

julia> replace(y, 999 => missing)
4-element Array{Union{Missing, Int64},1}:
 2
 5
  missing
 7

julia> replace!(y, 999 => missing)
ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type Int64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions