对于任何用例迭代数据帧时,它是否比itertuples更快?

时间:2017-09-27 10:48:01

标签: pandas dataframe

我在许多文档中都看到迭代在迭代数据帧时比iterrows快。但是在实现它时,itertuples相对较慢。我为此写了一个测试代码。有人可以解释

statusMarked = result6[result6.mapping_id_id == row.id]
time1_tup=time.time();
for index,row in statusMarked.iterrows():   
    ap_1=0
time2_tup=time.time()
for row in statusMarked.itertuples():    
    ap_2=0
time3_tup=time.time()
print "row time "
print time2_tup-time1_tup
print "tuple time "
print time3_tup-time2_tup
#iterrows took .00099 seconds but itertuples took .002 seconds

0 个答案:

没有答案