Accessing predefined array of DataFrame?

Hello!

Suppose I have a dataframe as such:

 df1
10×3 DataFrame
│ Row │ A     │ B      │ C        │
│     │ Int64 │ String │ Float64  │
├─────┼───────┼────────┼──────────┤
│ 1   │ 1     │ z      │ 0.907622 │
│ 2   │ 2     │ x      │ 0.547183 │
│ 3   │ 3     │ z      │ 0.4511   │
│ 4   │ 4     │ y      │ 0.645394 │
│ 5   │ 5     │ x      │ 0.697474 │
│ 6   │ 6     │ z      │ 0.277188 │
│ 7   │ 7     │ z      │ 0.346081 │
│ 8   │ 8     │ x      │ 0.516901 │
│ 9   │ 9     │ y      │ 0.738648 │
│ 10  │ 10    │ x      │ 0.663217 │

This dataframe exists inside one of my functions. Then I want to pass a variable, to denote which column I want to use, so for example;

plot_df(A)

Where it should plot my loaded dataframe column A. How do I do this properly? I am aware one when working with Dataframes can do, “df1.A”, but I can’t get this I described to work.

Kind regards

You could do:

plot_df(x, df) = plot(df[!, x])

but I guess this isn’t really a win over just doing plot(df[!, x]) directly?

2 Likes

Nono, that is great, exactly what I wanted. Thanks!

1 Like