# How to change value of Nullable{WeakRefString{UInt8}} using CSV package?

**URL:** https://discourse.julialang.org/t/how-to-change-value-of-nullable-weakrefstring-uint8-using-csv-package/6080
**Category:** Data
**Tags:** data
**Created:** [September 26, 2017, 10:13am UTC](https://discourse.julialang.org/t/how-to-change-value-of-nullable-weakrefstring-uint8-using-csv-package/6080 "2017-09-26T10:13:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)
#### Post date: [September 26, 2017, 10:13am UTC](https://discourse.julialang.org/t/how-to-change-value-of-nullable-weakrefstring-uint8-using-csv-package/6080/1 "2017-09-26T10:13:58Z")

</div>

Hi !

I try to work with the CSV package and I have some problem to change the value of a DataFrame entry because of the Nullable{WeakRefString{UInt8}} type.  
I do not know in advance the types of the columns so the default type for String is Nullable{WeakRefString{UInt8}}. I did not find a way to change any value of this type (see example below).

Thanks for your help !

```julia
julia> w = DataFrame(A = 1:4, B = ["M", "F", "F", "M"])
4×2 DataFrames.DataFrame
│ Row │ A │ B │
├─────┼───┼─────┤
│ 1 │ 1 │ "M" │
│ 2 │ 2 │ "F" │
│ 3 │ 3 │ "F" │
│ 4 │ 4 │ "M" │

julia> w[1,2]
"M"

julia> typeof(w[1,2])
String

julia> CSV.write("test/test.tsv", w, delim = sep, header = h)
CSV.Sink( CSV.Options:
        delim: '	'
        quotechar: '"'
        escapechar: '\\'
        null: ""
        dateformat: dateformat"yyyy-mm-dd", IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1), "test/test.tsv", 8, true, String["A", "B"], false)

julia> w = CSV.read("test/test.tsv"; delim = sep, header = h, null="NA")
4×2 DataFrames.DataFrame
│ Row │ A │ B │
├─────┼───┼─────┤
│ 1 │ 1 │ "M" │
│ 2 │ 2 │ "F" │
│ 3 │ 3 │ "F" │
│ 4 │ 4 │ "M" │

julia> typeof(w[1,2])
Nullable{WeakRefString{UInt8}}

julia> w[1,2] = "F"
ERROR: type String has no field data
Use `Vector{UInt8}(str)` instead.
Stacktrace:
 [1] setindex!(::NullableArrays.NullableArray{WeakRefString{UInt8},1}, ::String, ::Int64)

```

---

<div class="post-metadata">

### Author: ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)
#### Post date: [September 26, 2017, 11:59am UTC](https://discourse.julialang.org/t/how-to-change-value-of-nullable-weakrefstring-uint8-using-csv-package/6080/2 "2017-09-26T11:59:05Z")

</div>

You can do `CSV.read(file, weakrefstrings=false)`

---

<div class="post-metadata">

### Author: ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)
#### Post date: [September 26, 2017, 12:24pm UTC](https://discourse.julialang.org/t/how-to-change-value-of-nullable-weakrefstring-uint8-using-csv-package/6080/3 "2017-09-26T12:24:44Z")

</div>

> [@quinnj](#):
>
> weakrefstrings=false

Thank you Quinnj, it solves the problem 😉

---

<div class="post-metadata">

### Author: ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)
#### Post date: [September 26, 2017, 1:11pm UTC](https://discourse.julialang.org/t/how-to-change-value-of-nullable-weakrefstring-uint8-using-csv-package/6080/4 "2017-09-26T13:11:15Z")

</div>

Note that if you don’t have missing data in your files you can also use `nullable = false`, it will save you some troubles dealing with nullables.

---

<div class="post-metadata">

### Author: ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)
#### Post date: [September 26, 2017, 1:14pm UTC](https://discourse.julialang.org/t/how-to-change-value-of-nullable-weakrefstring-uint8-using-csv-package/6080/5 "2017-09-26T13:14:00Z")

</div>

> [@jonathanBieler](#):
>
> Note that if you don’t have missing data in your files you can also use nullable = false, it will save you some troubles dealing with nullables.

Thank you Jonathan, in my case, I have sometime missing values 🙂
