Hello everyone,
I’d just spent 5 hours on a simple issue with joining two dataframes.
I’ve basically two dataframes, one with a column of sectors and value, the other with new sectors mapped to the previous one as well as weights associated.
My issue is that I can’t perform leftjoin on the column sector in my real example, due to the error message “Cannot have duplicated names for indices”.
I’m not able to reproduce a MWE giving the same error message, but here an example of what I want to perform:
df_initial = DataFrame(code = ["a","b","c"],country = ["AU","AU","AU"] ,value = [10, 68, 50])
insertcols!(df_initial, :sector => string.(df_initial[:,:code], "-",df_initial[:,:country]))
df_weights = DataFrame(code = ["a","a","a","b","b","c"], country = ["AU","AU","AU","AU","AU","AU"],new_sector = ["new-1","new-2","new-3","new-4","new-2","new-1"], weights = [0.2, 0.2, 0.6, 0.4, 0.6, 1])
insertcols!(df_weights, :sector => string.(df_weights[:,:code], "-",df_weights[:,:country]))
df_test = leftjoin(df_weights[:,[:sector,:new_sector, :weights]], df_initial[:,[:sector,:value]], on = :sector)
Have you any idea of what can be the source of a potential “duplicated names for indices” message?