# Replace NULLs in DataTable

**URL:** <https://discourse.julialang.org/t/replace-nulls-in-datatable/2910>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 27, 2017, 5:18pm UTC](https://discourse.julialang.org/t/replace-nulls-in-datatable/2910 "2017-03-27T17:18:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abieler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abieler/32/2693_2.png) [@abieler](https://discourse.julialang.org/u/abieler)\
**Post date:** [March 27, 2017, 5:18pm UTC](https://discourse.julialang.org/t/replace-nulls-in-datatable/2910/1 "2017-03-27T17:18:24Z")

</div>

Alternatives to doing

> df[df[:A].isnull, :A] = newValue

for replacing NULLs in column :A of the DataTable df with “newValue”? From an earlier question I think that using .values and .isnull is not encouraged.  
Maybe an “impute()” function would be useful?

Thanks  
Andre

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 28, 2017, 11:52am UTC](https://discourse.julialang.org/t/replace-nulls-in-datatable/2910/2 "2017-03-28T11:52:22Z")

</div>

You can write `df[isnull.(df[:A]), :A] = newValue` to avoid accessing private fields.

But since there won’t be any missing values left in the column, you can also convert it to a standard `Array`. The conversion method accepts a second argument giving the value to replace nulls with: `df[:A] = convert(Array, df[:A], newValue)`.

We could provide a more discoverable and shorter function for that. dplyr uses `coalesce` (inspired from SQL), which can be passed either arrays or scalars. In the present case, passing a vector and a scalar would replace the nulls with the scalar.
