python - How to properly fetch single cells in pandas: loc[index,column] VS get_value(index,column) -
which method better (in terms of performance , reliability) use in order fetch single cells pandas dataframe
: get_value() or loc[]?
you can find info in docs in end:
for getting value explicitly (equiv deprecated df.get_value('a','a'))
# equivalent ``df1.at['a','a']`` in [55]: df1.loc['a', 'a'] out[55]: 0.13200317033032932
but if use there no warning.
but if check index.get_value
:
fast lookup of value 1-dimensional ndarray. only use if know you’re doing
so think better use iat
, at
, loc
, ix
.
timings:
df = pd.dataframe({'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9], 'd':[1,3,5], 'e':[5,3,6], 'f':[7,4,3]}) print (df) in [93]: %timeit (df.loc[0, 'a']) slowest run took 6.40 times longer fastest. mean intermediate result being cached. 10000 loops, best of 3: 177 µs per loop in [96]: %timeit (df.at[0, 'a']) slowest run took 17.01 times longer fastest. mean intermediate result being cached. 100000 loops, best of 3: 7.61 µs per loop in [94]: %timeit (df.get_value(0, 'a')) slowest run took 23.49 times longer fastest. mean intermediate result being cached. 100000 loops, best of 3: 3.36 µs per loop
Comments
Post a Comment