Select a data column with a name matching a row in Julia?

I have a large DataFrame that I import from a spreadsheet. I have the names of several columns that concern me in an array of rows. How to select a DataFrame column whose name matches the contents of a row? I would like something like this to work

using DataFrames df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"], C = 2:5) colsICareAbout = [":B" ":C"] df[:A] #This works df[colsICareAbout[1]] #This doesn't work 

Is there any way to do this?

+5
source share
1 answer

Strings are different from characters, but they are easy to convert.

 colsICareAbout = ["B","C"] df[symbol(colsICareAbout[1])] 

Keep in mind that it would be better to record in colsICareAbout characters for starters, but I don't know where your data colsICareAbout from.

+5
source

Source: https://habr.com/ru/post/1216112/


All Articles