# DataFrames Package: \`getindex(df::DataFrame, col\_inds::Union{AbstractVector, Regex, Not})\` is deprecated

**URL:** https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744
**Category:** General Usage
**Tags:** question, package
**Created:** [June 4, 2020, 4:19pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744 "2020-06-04T16:19:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![aebk2015](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@aebk2015](https://discourse.julialang.org/u/aebk2015)
#### Post date: [June 4, 2020, 4:19pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/1 "2020-06-04T16:19:07Z")

</div>

I just started reading [Julia for Machine Learning](https://technicspub.com/julia/). and I am getting a series of deprecated warning just from the DataFrames package:

The dataset the book uses for this example has to do with the strength of Wi-Fi signals from various devices to four rooms of a house and the CSV file can be obtained [here](http://bit.ly/2lOFOWm):

The first warning shows up after creating a new variable (RegressionTarget).

```julia
using CSV, StatsBase
df = CSV.read("localization.csv", header=false);
w = [5, 10, 15, 20]
df[:RegressionTarget] = Matrix(df[:, [1, 4, 6, 7]]) * w + randn(2000)

```

Coming from Pandas, at first I am confused as why the column name is not inside the " " but nevertheless, I am getting this warning:

```julia
┌ Warning: `setindex!(df::DataFrame, v::AbstractVector, col_ind::ColumnIndex)` is deprecated, use `begin
│ df[!, col_ind] = v
│ df
│ end` instead.
│ caller = top-level scope at In[10]:6
└ @ Core In[10]:6

```

Similarly, I get similar warning after running this:

`X = StatsBase.standardize(ZScoreTransform, map(Float64, Matrix(df[1:7])), dims=2)`

```julia
┌ Warning: `getindex(df::DataFrame, col_inds::Union{AbstractVector, Regex, Not})` is deprecated, use `df[:, col_inds]` instead.
│ caller = top-level scope at In[11]:1
└ @ Core In[11]:1

```

Can you explain how i should modify my code to get rid of these warnings?

I am running Julia 1.4 on macOS 10.15

Thanks,

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [June 4, 2020, 4:52pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/2 "2020-06-04T16:52:30Z")

</div>

The issue is how you are indexing `df`. It is now required to supply both row and column indexes when you index with brackets. So instead of saying `df[:RegressionTarget]` you need `df[!,:RegressionTarget]` or you can use the shorthand syntax more simply `df.RegressionTarget`.

Same thing with the second error message, `df[1:7]` should be `df[!,1:7]` assuming you want columns `1:7`.

---

<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: [June 4, 2020, 4:53pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/3 "2020-06-04T16:53:02Z")

</div>

Read the warning, it will give you the solution

```julia
use `df[:, col_inds]` instead.

```

---

<div class="post-metadata">

### Author: ![aebk2015](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@aebk2015](https://discourse.julialang.org/u/aebk2015)
#### Post date: [June 4, 2020, 4:58pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/4 "2020-06-04T16:58:49Z")

</div>

Thanks, it fixed the error. Can you tell me what the meaning of `:` before the `RegressionTarget` is?  
Also what is the difference between indexing by `:` vs `!` : i.e., `df[!, [1:7]]` vs `df[:, [1:7]]`

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [June 4, 2020, 6:13pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/5 "2020-06-04T18:13:51Z")

</div>

`:RegressionTarget` is a `Symbol`, ie equivalent to `Symbol("RegressionTarget")`

DataFrames.jl docs have more info on `!` vs `:` than I can give you.

---

<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: [June 4, 2020, 6:24pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/6 "2020-06-04T18:24:06Z")

</div>

See the documentation, [here](https://juliadata.github.io/DataFrames.jl/stable/lib/indexing/).

The `!` means that you get the vector without any copying. See the following:

```julia
julia> using DataFrames

julia> df = DataFrame(a = [1, 2, 3, 4], b = rand(4));

julia> x = df[!, :a];

julia> x[1] = 100
100

julia> df
4×2 DataFrame
│ Row │ a │ b │
│ │ Int64 │ Float64 │
├─────┼───────┼──────────┤
│ 1 │ 100 │ 0.40758 │
│ 2 │ 2 │ 0.943078 │
│ 3 │ 3 │ 0.189304 │
│ 4 │ 4 │ 0.434546 │

julia> y = df[:, :b];

julia> y[1] = 100
100

julia> df
4×2 DataFrame
│ Row │ a │ b │
│ │ Int64 │ Float64 │
├─────┼───────┼──────────┤
│ 1 │ 100 │ 0.40758 │
│ 2 │ 2 │ 0.943078 │
│ 3 │ 3 │ 0.189304 │
│ 4 │ 4 │ 0.434546 │

```

---

<div class="post-metadata">

### Author: ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)
#### Post date: [June 4, 2020, 6:28pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/7 "2020-06-04T18:28:01Z")

</div>

> [@aebk2015](#):
>
> Thanks, it fixed the error. Can you tell me what the meaning of `:` before the `RegressionTarget` is?

The number of rows, with : you are selecting all the rows.

> [@](#):
>
> Also what is the difference between indexing by `:` vs `!` : i.e., `df[!, [1:7]]` vs `df[:, [1:7]]`

The usage of memory, you should read [https://github.com/bkamins/Julia-DataFrames-Tutorial/](https://github.com/bkamins/Julia-DataFrames-Tutorial/), there is all information you could need.

---

<div class="post-metadata">

### Author: ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)
#### Post date: [June 4, 2020, 6:33pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/8 "2020-06-04T18:33:21Z")

</div>

Let me give you a brief overview of some of your questions.

Symbols in Julia i.e. `:symbol` are interned strings and are a way for the language to represent itself. So whem you type in `x = 0`, internally there is a symbol created called `:x` that is bound to the value 0. If you type in `eval(:x)` you’ll see it evaluate to zero. As to why column indexing in dataframes is done by symbols and not strings is probably internal performance issues.

Next is the notation `!`. In Julia it is customary to use `!` to annotate functions that modify their arguments. For example `fill(1.0, 10)` allocates a memory for a 10 element array. On the other other hand, `fill!(A, x)` fills a pre allocated array `A` with the value x. Note that it’s not a magical keyword; i.e you can’t just expect to add `!` to end of function names because the method may not exist.

Keeping in tune with this custom, `df[:, :column]` simply gets the column for you. On the other hand `df[!, :column] = values` assigns the array `values` to the column, and the `!` is simply there as a hint to users that something is being modified.

---

<div class="post-metadata">

### Author: ![aebk2015](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@aebk2015](https://discourse.julialang.org/u/aebk2015)
#### Post date: [June 4, 2020, 10:53pm UTC](https://discourse.julialang.org/t/dataframes-package-getindex-df-dataframe-col-inds-union-abstractvector-regex-not-is-deprecated/40744/9 "2020-06-04T22:53:22Z")

</div>

thanks, this really helped me understood this concept
