Can't convert column's data type from Char to Any

Hi! I was trying to change the data type of a column, but failed.

  1. Created a dataframe first:
using DataFrames
df = DataFrame(x = [1,2,3], y = ['a', 'b', 'c']);
  1. Then tried changing the data type of y column from Char to Any:
df[!, :y] = convert.(Any, df[!,:y])

Instead of getting converted, received following output:

3-element Vector{Char}:
 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
 'b': ASCII/Unicode U+0062 (category Ll: Letter, lowercase)
 'c': ASCII/Unicode U+0063 (category Ll: Letter, lowercase)

Will be a great help if solution is posted.

How about

df[!, :y] = Vector{Any}(df[!,:y])

?

3 Likes

Ya, it worked! Thanks a lot for helping out!

Also collect(Any, df.y).

3 Likes