Created
October 26, 2020 17:02
-
-
Save FBosler/def6d362e7f210716b052c552cb6e5d6 to your computer and use it in GitHub Desktop.
Apply / Lambda
This file contains hidden or 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
import numpy as np | |
import pandas as pd | |
samples = 100000 | |
df = pd.DataFrame( | |
{ | |
'col1':np.random.randint(2,100,samples), | |
'col2':np.random.randint(2,100,samples), | |
'col3':np.random.rand(samples) | |
} | |
) | |
df.col3 = df.col3.apply(lambda x: str(x).replace('.',',')) | |
%%timeit | |
results = [] | |
for _, row in df.iterrows(): | |
results.append(float(row.col3.replace(',','.'))) | |
%%timeit | |
results = df.col3.apply(lambda x: x.replace(',','.')).values |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment