My dataframe looks like this:
col1 col2 col3
Aba xxx yyy
bab bhh jjj
ccc kkk lll
Aba xxx yyy
ccc kkk jjj
I want to replace unique values of each column with something like:
In col1
: Aba
gets replaced with a0
,bab
gets replaced with a1
, ccc
gets replaced with a2
whereever it appears in the column.
Similarly with col2
: xxx
gets replaced with b0
,bhh
gets replaced with b1
etc.
In short first column starts replacing unique values with a0,a1,a2,a3
2nd one with b0,b1,b2,b3
, third column with c0,c1,c2
.. etc .
Looking for a solution in loop so that I can process all the columns and all the unique values all together coz I have more than a million rows.
Thanks,