Unsure how to solve error message when applying unstack to DataFrame

The error message tells you that two different values in the source data have the same string representation, so they produce duplicates in column names.

Here is a minimal example:

julia> df = DataFrame(x=[0, "0"])
2×1 DataFrame
 Row │ x
     │ Any
─────┼─────
   1 │ 0
   2 │ 0

julia> unstack(df, :x, :x, :x)
ERROR: ArgumentError: Non-unique column names produced. Non equal values in `colkey` were mapped to the same column name.

And the source of the problem is that 0 (number) and string "0" have the same string representation ("0").

1 Like