If you enjoyed VLOOKUP…

I’ve always enjoyed VLOOKUP in Excel so it was with great joy that I learned some new methods in Pandas this week. So much more flexible & powerful – what a pleasure!

.map()

For example, you have a list of names in one series and a list of clothing sizes in a second series:

To map them:

s_name.map(s_sizes)

Pandas looks up the value in s_names and tries to associate it with a corresponding index in s_sizes, returning the value from s_sizes if available.

The outcome:

.merge()

Even more powerful – I highly recommend the help page which explains copious possible scenarios super-clearly! So let’s say I have a list of grandmothers and mothers, and a second list of mothers and children – I want to combine the 2 lists so that I end up with a complete list of all grandmothers, mothers and children:

To merge the lists:

master = pd.merge(senior, junior, how = "right")

The outcome:

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: