Skip to content

PERF: series.map(arg) for category is slow if arg is a dict #23785

Closed
@colinfang

Description

@colinfang

Are the following 2 methods equivalent? I have to introduce a lambda to gain additional performance when dealing with map of category.

import pandas as pd
x = pd.Series(list('abcd') * 1000).astype('category')
mapper = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
%timeit x.map(mapper)
# 1000 loops, best of 3: 1.11 ms per loop
%timeit x.map(lambda a: mapper[a])
# 1000 loops, best of 3: 291 µs per loop

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions