Hi how’s it going?
I’m trying to write this recursive code out and can’t get it to work. Can someone help me with a solution? Here is a code of the scenario.
y = [2,2,2,2,3,3,4]
x = [1,2,3,3,2,2,2]
df = DataFrame(:column_1=>x,:column_2=>y)
df[!,:column_3] = string.(df[!,:column_1]).*string.(df[!,:column_2])
countmap(df[!,:column_3])
Dict{String,Int64} with 5 entries:
"32" => 2
"24" => 1
"12" => 1
"23" => 2
"22" => 1
What I’m looking for is that no value of column_3 has a count of 1 in the dataframe. If it is the case, then it should look either forward or backwards to rename to another value of :column_3, based on the two values that it was concatenated from. What I’m doing now is sorting by column 1, then identifying which values of column 3 has a count of 1, then trying to run a loop and replacing values then calling the function recursively, but I can’t get it.
For example, in the image, “12” only has 1 value, it should then look upwards to see if there’s a “22”, and since there is, it should rename to “22”. Similarly, “24” only has one value. It should look backwards and find that there is no “14” value so it checks the second part of the string concatenation and finds that there is a “23” value so it renames it to that.
A little complicated but essentially I just dont want any values of column_3 to have a count of 1 in the dataframe and it should adjust based on the closest numerical values pre-string concatenation.
Thank you!