# Dealing with NaN's

**URL:** <https://discourse.julialang.org/t/dealing-with-nans/60086>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [April 27, 2021, 7:50am UTC](https://discourse.julialang.org/t/dealing-with-nans/60086 "2021-04-27T07:50:31Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 27, 2021, 4:17pm UTC](https://discourse.julialang.org/t/dealing-with-nans/60086/21 "2021-04-27T16:17:45Z")

</div>

@sijo, the example provided had 10 rows for which:

```julia
julia> @btime filter(AsTable(:) => row->!any(isnan(x) for x in row), $df);
  5.400 μs (48 allocations: 4.34 KiB)

julia> @btime filter(row->!any(isnan(x) for x in row), $df);
  3.575 μs (41 allocations: 2.17 KiB)

julia> @btime filter((:) => (values...)->!any(isnan.(values)), $df);
  11.100 μs (59 allocations: 2.73 KiB)

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [April 27, 2021, 4:59pm UTC](https://discourse.julialang.org/t/dealing-with-nans/60086/22 "2021-04-27T16:59:01Z")

</div>

But for such small data frames performance doesn’t really matter?

I just realized the data frame has abstract columns (`Real`). Here are timings with `Float64` columns, for many rows:

```julia
julia> df = DataFrame(x=rand((-1.0,1.0,NaN),1000000), y=rand((-2.0,2.0,NaN),1000000), z=rand((-3.0,3.0,NaN),1000000));

julia> @btime filter(AsTable(:) => row->!any(isnan(x) for x in row), $df);
  16.694 ms (52 allocations: 32.06 MiB)

julia> @btime filter(row->!any(isnan(x) for x in row), $df);
  449.876 ms (10556281 allocations: 202.47 MiB)

julia> @btime filter((:) => (values...)->!any(isnan.(values)), $df);
  4.534 ms (29 allocations: 9.17 MiB)

```

And for a smaller dataset with many columns (here the compilation time is much longer):

```julia
julia> df = DataFrame([rand((-1.0,1.0,NaN)) for _ in 1:10, _ in 1:1000], :auto);

julia> @btime filter(AsTable(:) => row->!any(isnan(x) for x in row), $df);
  1.299 ms (12607 allocations: 1.16 MiB)

julia> @btime filter(row->!any(isnan(x) for x in row), $df);
  190.694 μs (2081 allocations: 145.98 KiB)

julia> @btime filter((:) => (values...)->!any(isnan.(values)), $df);
[compilation takes too long, I didn't wait]

```

[Previous page](https://discourse.julialang.org/t/dealing-with-nans/60086.md?page=1)
