I have a dataframe like as shown below
key, values_list
1, {'ABC':100}
2, {'DEF':100}
3, {'ASE':95,'ABC':5}
4, {'ABC':55,'ASE':40,'DEF':5}
5, {'DEF':90,'ABC':5,'ASE':2.5,'XYZ':2.5}
I would like to do the below
a) Convert dict values to string and include % symbol at the end of each string
So, I tried the below
df['values_list'].str.replace(r'[0-9]+', '[0-9]%') # Approach 1
np.where(df['values_list'].str.isdigit(),df['values_list']+'%',df['values_list']) #Approach 2
I expect my output to be like as below. You can see that we have % symbol for each numeric value.
key, values_list
1, {'ABC':100%}
2, {'DEF':100%}
3, {'ASE':95%,'ABC':5%}
4, {'ABC':55%,'ASE':40%,'DEF':5%}
5, {'DEF':90%,'ABC':5%,'ASE':2.5%,'XYZ':2.5%}