# How to select rows from a dataframe and then create a dataframe with multiple columns from the selection

**URL:** <https://discourse.julialang.org/t/how-to-select-rows-from-a-dataframe-and-then-create-a-dataframe-with-multiple-columns-from-the-selection/77652>\
**Category:** New to Julia\
**Tags:** dataframes\
**Created:** [March 9, 2022, 9:44pm UTC](https://discourse.julialang.org/t/how-to-select-rows-from-a-dataframe-and-then-create-a-dataframe-with-multiple-columns-from-the-selection/77652 "2022-03-09T21:44:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [March 9, 2022, 9:44pm UTC](https://discourse.julialang.org/t/how-to-select-rows-from-a-dataframe-and-then-create-a-dataframe-with-multiple-columns-from-the-selection/77652/1 "2022-03-09T21:44:43Z")

</div>

Hi all  
noob here

I can select the rows I want from a dataframe and create a new data using ONE of the original dataframes columns BUT how do I add TWO or more please?

so if test\_data has columns col1,col2,col3,col4,col5

and this creates df\_test with all the col1 with “TEST” in it.

```julia
df_test = test_data[test_data.col1 .== "TEST", :].col1

```

how do I add col3 and col5 to df\_test using the same line?

I tried

```julia
df_test = test_data[test_data.col1 .== "TEST", :].[col3, col5]

```

and it didn’t work.thanks for any help

---

<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:** [March 9, 2022, 9:56pm UTC](https://discourse.julialang.org/t/how-to-select-rows-from-a-dataframe-and-then-create-a-dataframe-with-multiple-columns-from-the-selection/77652/2 "2022-03-09T21:56:41Z")

</div>

```julia
df_test = test_data[test_data.col1 .== "TEST", ["col1", "col3", "col5"]]

```

or if you prefer to generate column names dynamically

```julia
df_test = test_data[test_data.col1 .== "TEST", string.("col", 1:2:5)]

```

In general data frame indexing has the following form:

```julia
source_data_frame[row_selector, column_selector]

```

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [March 9, 2022, 10:07pm UTC](https://discourse.julialang.org/t/how-to-select-rows-from-a-dataframe-and-then-create-a-dataframe-with-multiple-columns-from-the-selection/77652/3 "2022-03-09T22:07:00Z")

</div>

thank you so much. Worked like a champ. Really helpful answer.
