Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import timeit
- from math import log
- my_stat = pd.DataFrame({'x': np.random.random(size=10000)})
- def with_pd():
- my_stat['y'] = my_stat['x'].map(log)
- def with_pd_numexpr():
- my_stat.eval('y = log(x)', engine='numexpr', inplace=True)
- def with_np():
- my_stat['y'] = np.log(my_stat['x'])
- print(timeit.timeit('with_pd()', setup='from __main__ import with_pd', number = 100)) #0.525s
- print(timeit.timeit('with_pd_numexpr()', setup='from __main__ import with_pd_numexpr', number = 100)) #0.305s
- print(timeit.timeit('with_np()', setup='from __main__ import with_np', number = 100)) #0.122s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement