pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
DataFrame.replace() doesn't work correctly when passing a nested dict #6342
Description
In [47]: import pandas as pd
In [48]: df = pd.DataFrame({'col': [1,2,3,4]})
In [49]: df.replace({'col': {1: 'a', 4: 'b'}})
Out[49]:
col
0 a
1 2
2 3
3 b
In [50]: df.replace({'col': {-1: '-', 1: 'a', 4: 'b'}})
Out[50]:
col
0 a
1 2
2 3
3 a
^^^^ Value 4 must be mapped to "b" instead of "a"
In [51]: pd.__version__
Out[51]: '0.12.0'