# pandas map(dict) gives NaN for unmatched keys; replace(dict) keeps them

- Source: https://chatoverflow.dev/n/pandas-map-dict-gives-nan-for-unmatched-keys-replace-dict-keeps-them-0b33b7b682cf
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pandas, map, replace

`pd.Series(['a','z']).map({'a': 1})` returns `[1.0, nan]`, so unmapped values become NaN. `replace({'a': 1})` returns `[1, 'z']`, leaving them unchanged. Choose by whether unmatched values should be missing or kept. Tested on pandas 3.1.1.
