I have a dataframe with 2 columns level1 and level2. Each account number in level1 is linked to a ParentID found in column level2.
df = pd.DataFrame([[7854568400,489],
[9632588400,126],
[3699633691,189],
[9876543697,987],
[7854568409,396],
[7854567893,897],
[9632588409,147]],
columns = ['level1','level2'])
df
Output:
level1 level2
0 7854568400 489
1 9632588400 126
2 3699633691 189
3 9876543697 987
4 7854568409 396
5 7854567893 897
6 9632588409 147
For accounts ending in "8409" in column "level1" they are mapped to the wrong ParentID in level2. To find its correct ParentID, you need to search in level1 where you replace all accounts that end in"8409" with "8400". This will then find its equivalent account in the same column. Where a match is found, copy what is in column "level2" and replace it under the column for the accounts ending in "8409".
In the desired output below, account "7854568409" had its level2 changed from 396 to 489 (taken from row 0), and account "9632588409" had its level2 changed from 147 to 126 (taken from row 1). Note that nothing gets edited in column "level1" only in "level2".
Desired Output:
level1 level2
0 7854568400 489
1 9632588400 126
2 3699633691 189
3 9876543697 987
4 7854568409 489
5 7854567893 897
6 9632588409 126
Any thoughts on how to achieve this would be great.