Sameeresque
Sameeresque

Reputation: 2602

Giving a custom name for a column in dataframe, Julia

Defining a custom name joining certain previously defined strings like so:

df[:join([Str1,Str2,"_",Str3])] = zeros(length(df[:Str1]))

Returns the following error:

MethodError: objects of type Symbol are not callable

I understand that join doesn't work like that. Is it possible to convert join([Str1,Str2,"_",Str3]) to a variable?

Upvotes: 0

Views: 121

Answers (2)

Sameeresque
Sameeresque

Reputation: 2602

df[Symbol(join([Str1,Str2,"_",Str3]))] 

Does the job.

Upvotes: 0

user2510479
user2510479

Reputation: 1540

You can concatenate strings with the star * operator

field_name = "Str1" * "Str2" *"_"* "Str3"

or you can do it with string function

field_name = string("Str1","Str2","_","Str3")

Upvotes: 1

Related Questions