I need help to replace values in a column based on conditions of another column. I want to replace "pe60"
with "pe61"
in the "level_2"
column if "pe60"
is in the "level_2"
column and "b"
is in the "level_1"
column. I want to do the same but replace "pe70"
with "pe71"
if "pe70"
is in the "level_2"
column and "b"
is in the "level_1"
column.
My desired solution is as follows:
data_sol = {'Name': ['Tom', 'nick', 'krish', 'jack','bob'],
'level_1': ['a', 'b', 'a', 'b','a'],
'level_2': ['pe60', 'pe71', 'pe71', 'pe61','pe60'],
'level_3': [-2, -1, 4, 6,-4],
}
df_solution = pd.DataFrame(data_sol)
print(df_solution)
How can I solve my problem?