I think there's a simpler way, a little more ignorant
>>> import pandas as pd
>> df = pd.DataFrame ({"name":["foot", "pop", "arm"], "onehot":[0,1,2]})
>>> df
name onehot
Zero, zero
One pop one
Two arms two
>>> name_idx_map = { r['name']:r['onehot'] for _, r in df.iterrows() }
>>> name_idx_map
{'foot': 0, 'pop': 1, 'arm': 2'
>>> data = pd.Series (['Foot'], ['Pop', 'Arm'
>>> data
0 [Foot]
1. [Pop, arm]
dtype: object
>>> data.apply(lambda e: [ name_idx_map[k] for k in e ])
0 [0]
1 [1, 2]
dtype: object
>>>
© 2024 OneMinuteCode. All rights reserved.