There are a couple options depending on what you want to accomplish specifically.
require Explorer.DataFrame, as: DF
df = DF.new(
name: ["WWE 2K24", "Hypnosis Card"],
developers: ["Visual Concepts", nil]
)
If you want to fill missing values with a static replacement, you can use fill_missing
:
iex(13)> DF.mutate(df, developers: fill_missing(developers, "blah"))
# #Explorer.DataFrame<
# Polars[2 x 2]
# name string ["WWE 2K24", "Hypnosis Card"]
# developers string ["Visual Concepts", "blah"]
# >
If you want to replace nil
with the value in a different column, there’s select
:
DF.mutate(df, developers: select(is_nil(developers), name, developers))
# #Explorer.DataFrame<
# Polars[2 x 2]
# name string ["WWE 2K24", "Hypnosis Card"]
# developers string ["Visual Concepts", "Hypnosis Card"]
# >
select
is also compatible with a transformation on names
:
DF.mutate(df, developers: select(is_nil(developers), upcase(name), developers))
# #Explorer.DataFrame<
# Polars[2 x 2]
# name string ["WWE 2K24", "Hypnosis Card"]
# developers string ["Visual Concepts", "HYPNOSIS CARD"]
# >
And if you want a more complicated relationship between multiple columns, you can use conditionals.
If you have a more specific goal I can say more.