O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mapping data into different values

One of the basic tasks in data transformations is the mapping of a set of values to another set. Pandas provides a generic ability to map values using a lookup table (via a Python dictionary or a pandas Series) using the .map() method.

This method performs the mapping by first matching the values of the outer Series with the index labels of the inner Series. It then returns a new Series, with the index labels of the outer Series but the values from the inner Series.

The following example shows how to map the labels in the index of x to the values of y:

As with other alignment operations, if pandas does ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required