Lowercase dataframe column strings with missing values

I have a Data Frame with missing values on it.

using DataFrames

df = DataFrame(
    Y = ["A", "B", "C", "D", "E", "F"],
    Z = ["A", missing, "C", missing, "E", missing]
)

When I tried to transform to lowercase I got a MethodError: no method matching lowercase(::Missing) message, it doesn’t work because of the missing values:

transform(df, :Y => ByRow(x-> lowercase(x)) => :Y)

So I’m using:

broadcast(v -> ismissing(v) ? missing : lowercase(v), df[!, :Z]);
  • Is there any other simple option to transform a column to lowercase keeping the missing values as it is, something like df.Z.str.lower() and tolower(df$Z)?
  • Is it possible to use @pipe with the broadcast function above?

use the passmissing wrapper:

julia> transform(df, :Y => ByRow(passmissing(lowercase)) => :Y)
6×2 DataFrame
 Row │ Y       Z
     │ String  String?
─────┼─────────────────
   1 │ a       A
   2 │ b       missing
   3 │ c       C
   4 │ d       missing
   5 │ e       E
   6 │ f       missing