Created
September 25, 2017 16:28
-
-
Save leggitta/7a49f3d2d584a362c5b52a35051d93c6 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 numpy as np | |
import pandas as pd | |
import time | |
N = int(1e7) | |
M = 100 | |
counter = 0 | |
df = pd.DataFrame({'y1': np.zeros(N)}) | |
t0 = time.time() | |
while counter < N: | |
df['y1'].values[counter:counter+M] = counter | |
counter += M | |
tf = time.time() | |
print('update data frame:', tf - t0) | |
y = np.zeros(N) | |
t0 = time.time() | |
counter = 0 | |
while counter < N: | |
y[counter:counter+M] = counter | |
counter += M | |
df['y2'] = y | |
tf = time.time() | |
print('update array:', tf - t0) | |
assert (df.y1.values == df.y2.values).all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment