forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_get_put_value.py
48 lines (37 loc) · 1 KB
/
bench_get_put_value.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from pandas import *
from pandas.util.testing import rands
N = 1000
K = 50
def _random_index(howmany):
return Index([rands(10) for _ in xrange(howmany)])
df = DataFrame(np.random.randn(N, K), index=_random_index(N),
columns=_random_index(K))
def get1():
for col in df.columns:
for row in df.index:
_ = df[col][row]
def get2():
for col in df.columns:
for row in df.index:
_ = df.get_value(row, col)
def put1():
for col in df.columns:
for row in df.index:
df[col][row] = 0
def put2():
for col in df.columns:
for row in df.index:
df.set_value(row, col, 0)
def resize1():
buf = DataFrame()
for col in df.columns:
for row in df.index:
buf = buf.set_value(row, col, 5.)
return buf
def resize2():
from collections import defaultdict
buf = defaultdict(dict)
for col in df.columns:
for row in df.index:
buf[col][row] = 5.
return DataFrame(buf)