import numpy as np
import pandas as pd
import numexpr
import perfplot
import matplotlib.pyplot as plt
%matplotlib inline
np.random.seed(125)
def ne(x):
return x[numexpr.evaluate('(x > 5)')]
def bex(x):
return x[x.A.values > 5]
def be(x):
return x[x.A > 5]
def lc(x):
return x.loc[x.A > 5]
def lcx(x):
return x.loc[x.A.values > 5]
def q(x):
return x.query('A > 5')
def ev(x):
return x[x.eval('A > 5')]
def make_df(n):
df = pd.DataFrame(np.random.randint(10, size=n), columns=['A'])
return df
perfplot.show(
setup=make_df,
kernels=[ne, lc, lcx, be, bex, q, ev],
n_range=[2**k for k in range(2, 25)],
logx=True,
logy=True,
equality_check=False,
xlabel='len(df)')