A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/7333 below:

Series.map(dict) doesn't work when dict keys are tuples of length 1? · Issue #7333 · pandas-dev/pandas · GitHub

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4