# Broadcasting nothing to DataFrame entries raises MethodError

**URL:** https://discourse.julialang.org/t/broadcasting-nothing-to-dataframe-entries-raises-methoderror/66436
**Category:** New to Julia
**Created:** [August 15, 2021, 1:36pm UTC](https://discourse.julialang.org/t/broadcasting-nothing-to-dataframe-entries-raises-methoderror/66436 "2021-08-15T13:36:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![DaveTJones](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DaveTJones](https://discourse.julialang.org/u/DaveTJones)
#### Post date: [August 15, 2021, 1:36pm UTC](https://discourse.julialang.org/t/broadcasting-nothing-to-dataframe-entries-raises-methoderror/66436/1 "2021-08-15T13:36:48Z")

</div>

Hi, I’m learning my way around DataFrames.jl and CSV.jl and am having some difficulty understanding the behaviour of the following code;

```julia
using DataFrames, CSV

x = rand(5, 5)

A = DataFrame(x, :auto)

A[2:4, 2:4] .= missing

```

This code raises the error `'MethodError: Cannot 'convert' an object of type Missing to an object of type Float64'`.  
Elsewhere with real data I’m attempting to replace a block of erroneous entries in a dataframe with `nothing` to allow for easy interpolation using Impute.interp(). I’ve found it’s possible to do so using nested for loops, but I’m wondering why the broadcasting approach doesn’t work, since it seems more idiomatic.

---

<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: [August 15, 2021, 1:48pm UTC](https://discourse.julialang.org/t/broadcasting-nothing-to-dataframe-entries-raises-methoderror/66436/2 "2021-08-15T13:48:20Z")

</div>

I don’t see how it would work better with for loops: the problem is that `A` has columns of type `Float64` which cannot contain the `missing` value. You can fix it by calling `allowmissing!(A)` before the last line.

(I guess you meant `missing` instead of `nothing`? If you really want to use `nothing` I think you’ll have to construct the columns manually with type `Union{Nothing,Float64}`.)

---

<div class="post-metadata">

### Author: ![DaveTJones](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DaveTJones](https://discourse.julialang.org/u/DaveTJones)
#### Post date: [August 15, 2021, 2:03pm UTC](https://discourse.julialang.org/t/broadcasting-nothing-to-dataframe-entries-raises-methoderror/66436/3 "2021-08-15T14:03:47Z")

</div>

Yep, missing is what I had in mind. Thankyou. Is there any advantage to returning the type of the columns of `A` to `Float64` once the missing values have been imputed?

---

<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: [August 15, 2021, 2:06pm UTC](https://discourse.julialang.org/t/broadcasting-nothing-to-dataframe-entries-raises-methoderror/66436/4 "2021-08-15T14:06:19Z")

</div>

Probably for some things. But best not to worry about it until you actually need to improve performance.

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [August 15, 2021, 10:25pm UTC](https://discourse.julialang.org/t/broadcasting-nothing-to-dataframe-entries-raises-methoderror/66436/5 "2021-08-15T22:25:23Z")

</div>

> [@DaveTJones](#):
>
> returning the type of the columns of `A` to `Float64` once the missing values have been imputed?

How exactly did you intend to do so? If the `Vector` has `missing` values then it cannot be of type `Vector{Float64}`, it must be of type `Vector{Union{Missing, Float64}}`. An alternative would be using `NaN` instead of `missing`, as `NaN` is a `Float64` value, but `NaN` and `missing` have different meanings and behaviors.

---

<div class="post-metadata">

### Author: ![DaveTJones](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DaveTJones](https://discourse.julialang.org/u/DaveTJones)
#### Post date: [August 15, 2021, 11:11pm UTC](https://discourse.julialang.org/t/broadcasting-nothing-to-dataframe-entries-raises-methoderror/66436/6 "2021-08-15T23:11:24Z")

</div>

That’s very simple. `Impute.interp()` replaces each of the missing values with a real value, determined by linearly interpolating between the known values that bound the missing region. The end result is a dataframe that contains no missing entries.
