-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: DataFrame.replace with dict doesn't work when value=None #46606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
take |
Thanks @zeromh for the report
This does look like a documentation error. probably should be since also note that if you put a dict in the DataFrame then it still does not work...
because this is reserved for a special case where the values to replace are restricted to certain columns so this does work
so specifying a mapping for This gets more tricky with
which is then interpreted as a nested replacement dictionary so does not necessarily give the result expected and raises and if you have a
you get a RecursionError! whereas
does work. The docs for the nested dictionary case also probably need updating too |
take |
xref #46004 for related issue for Series. |
take |
take |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The documentation for DataFrame.replace says, for the
to_replace
argument, that:However, specifying
value=None
results in no replacement taking place. If I don't specifyvalue
at all, it works.Expected Behavior
I expect (based on the docs) that specifying
value=None
will allow using a dictionary for replacement.Installed Versions
INSTALLED VERSIONS
commit : 06d2301
python : 3.8.13.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.93-87.444.amzn2.x86_64
Version : #1 SMP Thu Jan 20 22:50:50 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.1
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : None
pytest : 7.1.1
hypothesis : None
sphinx : 4.5.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.1
IPython : 8.1.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : 0.8.1
fsspec : 2022.3.0
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 3.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
sqlalchemy : None
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: