# Overwrite partial DataFrame Row with new Array

**URL:** https://discourse.julialang.org/t/overwrite-partial-dataframe-row-with-new-array/27953
**Category:** Data
**Created:** [August 25, 2019, 1:14am UTC](https://discourse.julialang.org/t/overwrite-partial-dataframe-row-with-new-array/27953 "2019-08-25T01:14:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![milesf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milesf/32/9289_2.png) [@milesf](https://discourse.julialang.org/u/milesf)
#### Post date: [August 25, 2019, 1:14am UTC](https://discourse.julialang.org/t/overwrite-partial-dataframe-row-with-new-array/27953/1 "2019-08-25T01:14:56Z")

</div>

I’m attempting to overwrite the last two elements in a dataframe row with the contents of an array.

```julia
df = DataFrame([1 2 3])
df[1,2:3] = DataFrame([5 10])
ERROR: BoundsError: attempt to access "attempt to access a data frame with 2 columns at index 1"

```

If I attempt to overwrite the _first_ two elements (instead of the _last_ two), there are no errors.

```julia
df[1,1:2] = DataFrame([5 10])

```

I believe the first example used to work on earlier versions.

Also, is there any difference between these two techniques for converting an array to a dataframe?

```julia
array = [1 2 3]
convert(DataFrame, array)
DataFrame(array)

```

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [August 25, 2019, 1:31am UTC](https://discourse.julialang.org/t/overwrite-partial-dataframe-row-with-new-array/27953/2 "2019-08-25T01:31:41Z")

</div>

> [@milesf](#):
>
> ```julia
> array = [1 2 3]
> convert(DataFrame, array)
> DataFrame(array)
> 
> ```

are equivalent.

> [@milesf](#):
>
> ```julia
> df[1,2:3] = DataFrame([5 10])
> 
> ```

will not be allowed, because LHS is 1-dimensional (`DataFrameRow`), and RHS is 2-dimensional (`DataFrame`).

In the 0.20 release of DataFrames.jl you will be able to put any iterable object to a `DataFrameRow` via `setindex!`. For now, what you can do is use broadcasting assignment:

```julia
df[1,2:3] .= [5, 10]

```

CC @nalimilan - the inconsistency @milesf notices is due to the fact that `DataFrame` has `length` defined. That is why I want to end deprecation period in [https://github.com/JuliaData/DataFrames.jl/pull/1899](https://github.com/JuliaData/DataFrames.jl/pull/1899) PR (as discussed in [target setindex implementation by bkamins · Pull Request #1899 · JuliaData/DataFrames.jl · GitHub](https://github.com/JuliaData/DataFrames.jl/pull/1899#discussion_r317367048) coment).

---

<div class="post-metadata">

### Author: ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)
#### Post date: [August 25, 2019, 1:43am UTC](https://discourse.julialang.org/t/overwrite-partial-dataframe-row-with-new-array/27953/3 "2019-08-25T01:43:40Z")

</div>

Writing on behalf of @bkamins, as he has no Internet access now.

After the analysis (he was using a development branch in tests of your code). The code

```julia
df[1,2:3] = DataFrame([5 10])

```

should not be used (it is deprecated), but it should work correctly on 0.19 version. The reason why it fails is a bug in deprecation code. He will submit a PR to fix this.

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [August 25, 2019, 10:46am UTC](https://discourse.julialang.org/t/overwrite-partial-dataframe-row-with-new-array/27953/4 "2019-08-25T10:46:48Z")

</div>

See [https://github.com/JuliaData/DataFrames.jl/pull/1928](https://github.com/JuliaData/DataFrames.jl/pull/1928). You can use the fix I have used there already now if you really need to use 1-row DataFrame on RHS (but I would not recommend doing this as the support for this will be soon removed).
