remap

Remap values in pandas column with a dict, preserve NaNs

Remap values in pandas column with a dict, preserve NaNs Question: I have a dictionary which looks like this: di = {1: "A", 2: "B"} I would like to apply it to the col1 column of a dataframe similar to: col1 col2 0 w a 1 1 2 2 2 NaN to get: col1 col2 …

Total answers: 12