So I have the following dataframe
import pandas as pd
df = pd.DataFrame({'ID': [ 0 , 1 , 2 , 3 ],
'name': ['A', 'B', 'C', 'D'],
'parent': [ '', 'A', 'A', 'B']})
Now as you see there is a parent-child hierarchy in here. However, unfortunately this is based on strings.
Is it possible to very effectively / neatly to create a new column with the actual numeric parent id?
E.g. the result would be;
df = pd.DataFrame({'ID': [ 0 , 1 , 2 , 3 ],
'name': [ 'A', 'B', 'C', 'D'],
'parent': [ '', 'A', 'A', 'B'],
'parentID': [None, 0, 0, 1 ]})