# Replacing \*missing\* and \*NaN\* values in dataframe

**URL:** <https://discourse.julialang.org/t/replacing-missing-and-nan-values-in-dataframe/78687>\
**Category:** New to Julia\
**Tags:** question, dataframes, missing-values\
**Created:** [March 29, 2022, 4:13pm UTC](https://discourse.julialang.org/t/replacing-missing-and-nan-values-in-dataframe/78687 "2022-03-29T16:13:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 29, 2022, 4:18pm UTC](https://discourse.julialang.org/t/replacing-missing-and-nan-values-in-dataframe/78687/2 "2022-03-29T16:18:28Z")

</div>

Your indexing does not make sense: what is `df_i.col` supposed to mean?

```julia
julia> df_i.col
ERROR: ArgumentError: column name :col not found in the data frame

```

To replace all missings use `coalesce`:

```julia
julia> coalesce.(df_i, 0.0)
5×4 DataFrame
 Row │ id name age salary
     │ Int64 Any Float64 Float64
─────┼───────────────────────────────
   1 │ 101 A 28.0 3200.0
   2 │ 102 B 32.0 3200.0
   3 │ 103 C 0.0 4500.0
   4 │ 104 NaN NaN 0.0
   5 │ 105 E 31.0 0.0

```

if you want to loop over columns, just do so directly:

```julia
julia> for c ∈ eachcol(df_i)
           replace!(c, NaN => 0.0)
       end

```

I’d also recommend going through [https://github.com/bkamins/Julia-DataFrames-Tutorial](https://github.com/bkamins/Julia-DataFrames-Tutorial) to get the hang of DataFrames

---

_[View the full topic](https://discourse.julialang.org/t/replacing-missing-and-nan-values-in-dataframe/78687)._
