Skip to content

Instantly share code, notes, and snippets.

@straussmaximilian
Created September 21, 2019 12:59
Show Gist options
  • Save straussmaximilian/ad7e436eae64a274b598a33bd6204f59 to your computer and use it in GitHub Desktop.
Save straussmaximilian/ad7e436eae64a274b598a33bd6204f59 to your computer and use it in GitHub Desktop.
#Pandas
import pandas as pd
df = pd.DataFrame({'x': array[:, 0], 'y': array[:, 1], 'z': array[:, 2]})
# Pandas query
print('Pandas Query:\t\t', end='')
%timeit df.query('x >= 0.2 and x <= 0.4 and y >= 0.4 and y <= 0.6')
# Pandas eval
print('Pandas Eval:\t\t', end='')
%timeit df.eval('x >= 0.2 and x <= 0.4 and y >= 0.4 and y <= 0.6')
# Boolean index
print('Pandas Boolean index:\t', end='')
%timeit df[(df['x'] >= 0.2) & (df['y'] >= 0.4) & (df['x'] <= 0.4) & (df['y'] <= 0.6)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment