Hey all, I am trying to write a single string to one cell in a large CSV made up entirely of numbers Julia reads in as Floats when copying the CSV into a dataframe. I want to overwrite one value within the csv with a string without changing the rest of the CSV, but due to the rest of the column having type Float64 in the dataframe version of the CSV, I have not been able to do so with the standard dataframe accessing by index. Do people have any suggestions as to how I might get around this issue?
You could use a Union
type for the column to make assignment of a string a valid operation:
julia> df = DataFrame(a = 1:3, b = rand(3))
3Ć2 DataFrame
Row ā a b
ā Int64 Float64
āāāāāā¼āāāāāāāāāāāāāāāāā
1 ā 1 0.644675
2 ā 2 0.754814
3 ā 3 0.458067
julia> df.b = convert(Vector{Union{Float64,String}}, df.b);
julia> df.b[2] = "zeroish"
"zeroish"
julia> CSV.write("test.csv", df)
"test.csv"
julia> readlines("test.csv")
4-element Vector{String}:
"a,b"
"1,0.6446749255742438"
"2,zeroish"
"3,0.4580669558867503"
2 Likes