Created
November 29, 2017 07:26
-
-
Save MartinThoma/e320cbb937afb4ff766f75988f1c65e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""What is the difference between map and apply?""" | |
import pandas as pd | |
df = pd.DataFrame([(1, 2, 3), (5, 6, 7), (9, 0, 1), (3, 4, 5)], | |
columns=list('abc'), | |
index=['India', 'France', 'England', 'Germany']) | |
df['b'] = df['a'] | |
df['c'] = df['a'] | |
print(df) | |
# Is there a difference between .map and .apply? | |
df['b'] = df['b'].map(lambda x: x**2) | |
df['c'] = df['c'].apply(lambda x: x**2) | |
print(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment