# Nan Error in CSV

**URL:** <https://discourse.julialang.org/t/nan-error-in-csv/49197>\
**Category:** New to Julia\
**Tags:** question, function\
**Created:** [October 28, 2020, 6:24pm UTC](https://discourse.julialang.org/t/nan-error-in-csv/49197 "2020-10-28T18:24:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yasser\_rajwani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yasser_rajwani/32/14278_2.png) [@yasser\_rajwani](https://discourse.julialang.org/u/yasser_rajwani)\
**Post date:** [October 28, 2020, 6:24pm UTC](https://discourse.julialang.org/t/nan-error-in-csv/49197/1 "2020-10-28T18:24:20Z")

</div>

I have a CSV file which contains about 1500 values some of which are “nan”, I am trying to write a function that would replace the “nan” values with zero.

I tried using the replace\_nan(v) and CSV write function, however have been unsuccesful.

P.S. I am julia beginer, so any help will be appreicated.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [October 28, 2020, 6:42pm UTC](https://discourse.julialang.org/t/nan-error-in-csv/49197/2 "2020-10-28T18:42:18Z")

</div>

One thing you could do is use `missingstring = "nan"` to read in the NaN values as `missing`, then perform `replace(col, missing => NaN)` on all the columns that should have `NaN` values.

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [October 28, 2020, 10:30pm UTC](https://discourse.julialang.org/t/nan-error-in-csv/49197/3 "2020-10-28T22:30:33Z")

</div>

`replace(x, NaN => 0)`, (or `replace!(x, NaN => 0)` if you want to do in-place replacement) should work in many circumstances. Can you post a minimum reproducible example where that does not work?

Please consider the following recommendations to post your example:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …
