# How to select all columns instead of one in a dataframe?

**URL:** <https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 10, 2017, 12:22pm UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196 "2017-06-10T12:22:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saran\_S](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saran_s/32/1155_2.png) [@Saran\_S](https://discourse.julialang.org/u/Saran_S)\
**Post date:** [June 10, 2017, 12:22pm UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196/1 "2017-06-10T12:22:32Z")

</div>

Hello,  
Is there a way to select all dataframe except one single column?  
Below is my dataframe.

```julia
10×5 DataFrames.DataFrame
│ Row │ SepalLength │ SepalWidth │ PetalLength │ PetalWidth │ Species │
├─────┼─────────────┼────────────┼─────────────┼────────────┼──────────┤
│ 1 │ 5.1 │ 3.5 │ 1.4 │ 0.2 │ "setosa" │
│ 2 │ 4.9 │ 3.0 │ 1.4 │ 0.2 │ "setosa" │
│ 3 │ 4.7 │ 3.2 │ 1.3 │ 0.2 │ "setosa" │
│ 4 │ 4.6 │ 3.1 │ 1.5 │ 0.2 │ "setosa" │
│ 5 │ 5.0 │ 3.6 │ 1.4 │ 0.2 │ "setosa" │
│ 6 │ 5.4 │ 3.9 │ 1.7 │ 0.4 │ "setosa" │
│ 7 │ 4.6 │ 3.4 │ 1.4 │ 0.3 │ "setosa" │
│ 8 │ 5.0 │ 3.4 │ 1.5 │ 0.2 │ "setosa" │
│ 9 │ 4.4 │ 2.9 │ 1.4 │ 0.2 │ "setosa" │
│ 10 │ 4.9 │ 3.1 │ 1.5 │ 0.1 │ "setosa" │

```

If i want to all columns except `:PetalWidth` . Is there a way to achieve this instead of writing all the column names other the

`iris_1 = iris[[:SepalLength,:SepalWidth,:PetalLength,:Species]]`

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 10, 2017, 1:11pm UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196/2 "2017-06-10T13:11:57Z")

</div>

```julia
julia> df = dataset("datasets", "iris");

julia> df[filter(x -> x != :PetalWidth, names(df))]

```

---

<div class="post-metadata">

**Author:** ![Saran\_S](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saran_s/32/1155_2.png) [@Saran\_S](https://discourse.julialang.org/u/Saran_S)\
**Post date:** [June 10, 2017, 1:20pm UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196/3 "2017-06-10T13:20:24Z")

</div>

Thank You.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [June 10, 2017, 3:36pm UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196/4 "2017-06-10T15:36:46Z")

</div>

Another, slightly shorter solution:

```julia
df[setdiff(names(df), [:PetalWidth])]

```

---

<div class="post-metadata">

**Author:** ![Saran\_S](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saran_s/32/1155_2.png) [@Saran\_S](https://discourse.julialang.org/u/Saran_S)\
**Post date:** [June 11, 2017, 11:22am UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196/5 "2017-06-11T11:22:15Z")

</div>

> [@nalimilan](#):
>
> df[setdiff(names(df), [:PetalWidth])]

Good to have alternative method. Thank 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:** [May 15, 2018, 3:46pm UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196/6 "2018-05-15T15:46:12Z")

</div>

Is there a way to do this using Regex with a DataFrame?

It’s a bit difficult since as far as I can tell you can’t perform regex on a symbol, you have to convert all column names to strings first. DataFramesMeta doesn’t have that functionality, but such functionality should probably live in there. Something like

```julia
select(df, :x2, :x2, r"^y")

```

Would evaluate if a keyword argument is a `Regex` then find all the names in `df` matching that regex, then collect all the other arguments and call `df[args]`.

The mix of Symbol and Regex would be to emulate Stata, where you can do

```julia
keep id_variable x1 x2 y*

```

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [May 15, 2018, 5:04pm UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196/7 "2018-05-15T17:04:00Z")

</div>

If anybody is up for implementations. it’d be probably good to be consistent with the JuliaDB syntax for these operations:

[http://juliadb.org/latest/api/selection.html#Column-special-selection-1](http://juliadb.org/latest/api/selection.html#Column-special-selection-1)

For regexes it is `select(t, r"^y")`, I’ve only now noticed it’s not documented.

---

<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:** [May 15, 2018, 7:11pm UTC](https://discourse.julialang.org/t/how-to-select-all-columns-instead-of-one-in-a-dataframe/4196/8 "2018-05-15T19:11:01Z")

</div>

Thanks, ill look at this.

BTW, i’m still confused, is there a manifesto somewhere that delineates the use cases of JuliaDB and DataFrames? It feels like JuliaDB is uniformly upstream of DataFrames, but its not clear how.
