Created
December 21, 2016 08:47
-
-
Save prashnts/e61b49bcc424fb042677eb1eff3edf51 to your computer and use it in GitHub Desktop.
Perf comparison when using Integer vs. String indexes in a Pandas DF
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 pandas as pd | |
import numpy as np | |
LIM = 100000 | |
df_i = pd.DataFrame(np.random.randint(0, 100, size=(LIM, 4)), columns=list('ABCD'), index=list(range(0, LIM))) | |
df_s = pd.DataFrame(np.random.randint(0, 100, size=(LIM, 4)), columns=list('ABCD'), index=list(map(hex, range(0, LIM)))) | |
## used in ipython | |
>>> %timeit -n 100 df.sort_values('A') | |
100 loops, best of 3: 10.6 ms per loop | |
>>> %timeit -n 100 df_s.sort_values('A') | |
100 loops, best of 3: 18.1 ms per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment