Closed
Description
I ran across an odd issue today where some analysis code that was working pre-pandas 0.14.0 started failing. The issue seems to be specific to trying to use Series.map(some_dict)
when the dict keys (and values in the series) are single item tuples. Code to demonstrate the issue:
import pandas as pd
pd.version.version
Out[10]: '0.14.0'
df = pd.DataFrame({'a': [(1,), (2,), (3, 4), (5, 6)]})
label_mappings = {
(1,): 'A',
(2,): 'B',
(3, 4): 'A',
(5, 6): 'B'
}
df['labels'] = df['a'].map(label_mappings)
df
Out[7]:
a labels
0 (1,) NaN
1 (2,) NaN
2 (3, 4) A
3 (5, 6) B
The expected output here is:
df
Out[7]:
a labels
0 (1,) A
1 (2,) B
2 (3, 4) A
3 (5, 6) B