pd.Series.map never maps NAs through a dictionary · Issue #17648 · pandas-dev/pandas (original) (raw)
Code Sample
import pandas as pd, numpy as np print(pd.Series([1, 2, np.nan]).map({1: "a", 2: "b", np.nan: "c"}))
This prints:
0 a
1 b
2 NaN
dtype: object
Problem description
The parameter na_action
of pd.Series.map
is ignored if the first argument of map
is a dictionary. Rather than mapping NAs if na_action
is None
and passing them through unaltered if it's "ignore"
, pandas always passes NAs through unaltered, as if na_action
were "ignore"
. (The default is None
.)
Expected Output
0 a
1 b
2 c
dtype: object
Output of pd.show_versions()
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.10.0-33-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.20.3
pytest: 3.0.7
pip: 9.0.1
setuptools: 36.0.1
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: None
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: None
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.9.5
s3fs: None
pandas_gbq: None
pandas_datareader: None