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

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

or if you prefer to generate column names dynamically

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

In general data frame indexing has the following form:

source_data_frame[row_selector, column_selector]
1 Like