# Replacing one value in a large csv of floats with a string

**URL:** <https://discourse.julialang.org/t/replacing-one-value-in-a-large-csv-of-floats-with-a-string/76197>\
**Category:** General Usage\
**Tags:** csv, data\_structures\
**Created:** [February 10, 2022, 11:52pm UTC](https://discourse.julialang.org/t/replacing-one-value-in-a-large-csv-of-floats-with-a-string/76197 "2022-02-10T23:52:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikel8](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mikel8](https://discourse.julialang.org/u/mikel8)\
**Post date:** [February 10, 2022, 11:52pm UTC](https://discourse.julialang.org/t/replacing-one-value-in-a-large-csv-of-floats-with-a-string/76197/1 "2022-02-10T23:52:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [February 11, 2022, 12:06am UTC](https://discourse.julialang.org/t/replacing-one-value-in-a-large-csv-of-floats-with-a-string/76197/2 "2022-02-11T00:06:23Z")

</div>

You could use a `Union` type for the column to make assignment of a string a valid operation:

```julia
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"
```
