Skip to content

Instantly share code, notes, and snippets.

@leggitta
Created September 25, 2017 16:28
Show Gist options
  • Save leggitta/7a49f3d2d584a362c5b52a35051d93c6 to your computer and use it in GitHub Desktop.
Save leggitta/7a49f3d2d584a362c5b52a35051d93c6 to your computer and use it in GitHub Desktop.
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