For Example:
col1 |
---|
'ACDE' |
'ADEC' |
I have:
A = 0.89
C = 1.21
D = 1.33
E = 1.47
So the column should become
col1 |
---|
[0.89, 1.21, 1.33, 1.47] |
['0.89','1.33','1.47','1.21'] |
For Example:
col1 |
---|
'ACDE' |
'ADEC' |
I have:
A = 0.89
C = 1.21
D = 1.33
E = 1.47
So the column should become
col1 |
---|
[0.89, 1.21, 1.33, 1.47] |
['0.89','1.33','1.47','1.21'] |
You should really not try to access variables by a string representation of their name.
Use a dictionary as container:
d = {'A': 0.89, 'C': 1.21, 'D': 1.33, 'E': 1.47}
# or
d = {'A': A, 'C': C, 'D': D, 'E': E}
Then you can break your string into characters and map
the values:
df['col1'] = df['col1'].str.extractall('(.)')[0].map(d).groupby(level=0).agg(list)
Or using a list comprehension:
df['col1'] = [[d.get(c) for c in s] for s in df['col1']]
output:
col1
0 [0.89, 1.21, 1.33, 1.47]
1 [0.89, 1.33, 1.47, 1.21]