I have a complicated nested dictionary which I have to use to replace values in specific columns.
dict_map = {
'ColA' : {('A','Distinct (Highest)','B','C'):'Pass'},
'ColB' : {'Great': 'A', 'Avg': 'Average', 'F (Absent)': 'Fail'}
}
cols_to_map = ['ColA','ColB']
new_cols = ['ColA-new','ColB-new']
df = pd.DataFrame(
{
'ID': ['AB01', 'AB02', 'AB03', 'AB04', 'AB05','AB06'],
'ColA': ["A","B","A",np.nan,
"C",np.nan],
'ColB': ['Great', 'Avg', np.nan, np.nan, 'F (Absent)', np.nan]
})
The output dataframe must contain the 2 new columns, along with the existing data. How can I achieve this in python?