LoadError: ArgumentError: syntax df[column] is not supported use df[!, column] instead


I want to create a dictionary that contains other dictionaries.
The code is as follows:

df_events_sim = DataFrame(XLSX.readtable("path/df_events_sim.xlsx","Sheet1")...)
df_betas_duels = DataFrame(XLSX.readtable("path/df_betas_duels.xlsx","Sheet1")...)

players = string.(unique(df_events_sim[:,:playerId])) 
duels = string.(unique(df_events_sim[:,:playerId]))
zones_i = ["beta_zones_i_1", "beta_zones_i_2", "beta_zones_i_3", "beta_zones_i_4", "beta_zones_i_5", "beta_zones_i_6", "beta_zones_i_7", "beta_zones_i_8",
            "beta_zones_i_9", "beta_zones_i_10", "beta_zones_i_11", "beta_zones_i_12"]
times = ["beta_times_1", "beta_times_2", "beta_times_3", "beta_times_4", "beta_times_5", "beta_times_6", "beta_times_7"]
res = ["beta_res_1", "beta_res_2", "beta_res_3"]
loc = ["beta_loc_1", "beta_loc_2"]

dict_duels_accurate_probs = Dict()
alpha = df_betas_duels[df_betas_duels[:var] .== "alpha",:]["mean"][1]
epsilon = df_betas_duels[df_betas_duels[:var] .== "epsilon",:]["mean"][1]
for (i, item1) in enumerate(players)
    dict_duels_accurate_probs[item1] = Dict()
    for (j, item2) in enumerate(duels)
        dict_duels_accurate_probs[item1][item2] = Dict()
        for (k, item3) in enumerate(zones_i)
            dict_duels_accurate_probs[item1][item2][item3] = Dict()
            for (l, item4) in enumerate(times)
                dict_duels_accurate_probs[item1][item2][item3][item4] = Dict()
                for (m, item5) in enumerate(res)
                    dict_duels_accurate_probs[item1][item2][item3][item4][item5] = Dict()
                    for (n, item6) in enumerate(loc)
                        b_player = df_betas_duels[df_betas_duels[:id] .== string(item1),:]["mean"][1]
                        b_duels = df_betas_duels[df_betas_duels[:duels] .== string(item2),:]["mean"][1]
                        b_zone = df_betas_duels[df_betas_duels[:var] .== item3,:]["mean"][1]
                        b_time = df_betas_duels[df_betas_duels[:var] .== item4,:]["mean"][1]
                        b_res = df_betas_duels[df_betas_duels[:var] .== item5,:]["mean"][1]
                        b_loc = df_betas_duels[df_betas_duels[:var] .== item6,:]["mean"][1]
                        aux = exp(alpha+b_player+b_duels+b_zone+b_time+b_res+b_loc)
                        prob = aux/(1+aux)
                        dict_duels_accurate_probs[item1][item2][item3][item4][item5][item6] = prob

But it throws me this error:

ERROR: LoadError: ArgumentError: syntax df[column] is not supported use df[!, column] instead
 [1] getindex(::DataFrame, ::Symbol) at /home/smena/.julia/packages/DataFrames/3mEXm/src/abstractdataframe/abstractdataframe.jl:1996
 [2] top-level scope at /home/smena/betas_duels.jl:30
 [3] include(::Function, ::Module, ::String) at ./Base.jl:380
 [4] include(::Module, ::String) at ./Base.jl:368
 [5] exec_options(::Base.JLOptions) at ./client.jl:296
 [6] _start() at ./client.jl:506
in expression starting at /home/smena/betas_duels.jl:30

What am I doing wrong?

I think the error message says it all: You are trying to access a column of a DataFrame.
The syntax df.A works, but the syntax df[:A] does not.
So you need to replace
df_betas_duels[idx]["mean"] with df_beta_duels[idx, "mean"] where
idx = df_beta_duels[!, :id] .== string(item1).

PS: A MWE would have been helpful. I might misunderstand the structure of your data.

1 Like