I have to create a set of DataFrames based off of the entries of an existing DataFrame. One way to approach would be to create a function that turns the entires in a DataFrame into variables and then assign values to them.
artist = DataFrame("A" =>["Bob Marley", "Kiiara", "Sinead"])
function discography(artist)
for i = artist
@eval $(Symbol(i)) = DataFrame("songs"=>[],"concerts" =>[])
end
end
discography(artist.A)
I actually have a two questions about this.
-
I saw in another post that one should avoid using @eval until you thoroughly understand it because of its global scope, so I was wondering if there was a better way to do this without using @eval or affecting the entire module.
-
In general is it bad practice to name things after values in DataFrame entries? I read in another post that dynamically naming things is frowned upon because it can lead to bugs in the code. Iβm not sure if there is a less clunky approach that is generally taken when a new DataFrame needs to be created based off of entries of an existing one and stored?