Julia1
1
Hi, I may be overthinking this one, but all I’m trying to do is turn a column into a specific indexed substring of that column.
df = DataFrame(number=[123456,134553])
df[:number] = string.(df[:number]
All I want to do is return the first 3 digits of each row value for the numbers column, in this case “123” and “134”.
Thanks
nilshg
2
julia> getindex.(string.(a), Ref(1:3))
2-element Array{String,1}:
"123"
"134"
Note, you should be using the non-deprecated indexing behavior for data frames, i.e. df[:, :number]
or df.number
julia> df.str_sub_number = SubString.(string.(df.number), 1, 3)
If you don’t want to worry about SubString
s, do
julia> df.str_sub_number = getindex.(string.(df.number), Ref(1:3))
2 Likes