I am trying to create a new concatenated variable for each row in my merged dataframe. The concatenated names will be based on the table names with respect to the table index and parent index. The parent index acts as a map for the table index. Here's what my tables look like:
Table Index ParentIndex TableName
0 -1 ingredient
1 0 salt
2 0 pepper
3 1 butter
df0
FieldIndex TableIndex FieldName
0 1 afield
1 3 anotherfield
2 2 afield
df1
I have merged the dataframes on TableIndex. The desired output would be something like this:
TableIndex ParentIndex FieldIndex FieldName ConcatNames
1 0 0 afield ingredient.salt.afield
3 1 1 anotherfield ingredient.salt.butter.anotherfield
2 0 2 afield ingredient.pepper.afield
As you can see, the ParentIndex is sort of a composite function for TableIndex until it reaches -1 (and does not have to be included in the final output). I am not sure how to go about this. Could this be achieved using something like df.index.map or pd.IntervalIndex? This is also not the only file, and table names vary for each.