Skip to content

DataFrame.replace() doesn't work correctly when passing a nested dict #6342

Closed
@estevopaz

Description

@estevopaz
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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions