Created
July 27, 2020 06:51
-
-
Save naenumtou/cd7434b27a34ac67671e3fcd64f9565c 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
import pandas as pd | |
import numpy as np | |
import time | |
#Mock data | |
data = np.random.randint(0,100,size = (2**20, 1)) | |
df = pd.DataFrame(data, columns = ['test']) | |
#Pandas apply | |
s = time.time() | |
def checking(df): | |
if df['test'] < 50: | |
flag = 1 | |
else: | |
flag = 0 | |
return flag | |
df['apply_1'] = df.apply(checking, axis = 1) | |
e = time.time() | |
print('Apply 1 time = {}'.format(e-s)) | |
s = time.time() | |
def checking2(df): | |
if df['test'] < 30: | |
flag = 1 | |
elif df['test'] < 50: | |
flag = 2 | |
else: | |
flag = 3 | |
return flag | |
df['apply_2'] = df.apply(checking2, axis = 1) | |
e = time.time() | |
print('Apply 2 time = {}'.format(e-s)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment