如何使此条件工作更快?

时间:2019-10-24 11:10:13

标签: python pandas

数据帧称为seg

条件如下。

for i in list(range(0,seg.shape[0])):
if seg.loc[i,"col1"] >= 1 and seg.loc[i,"col2"] == 0.0 :
    seg.loc[i, "col3"] = "C"
if seg.loc[i,"col1"] >= 1 and seg.loc[i,"col2"] >= 1.0 :
    seg.loc[i, "col3"] = "M"
if seg.loc[i,"col1"] == 0 and seg.loc[i,"col2"] >= 1.0 :
    seg.loc[i, "col3"] = "D"

这种方式需要大量时间来进行操作。该数据框有超过一千万行

谢谢!

0 个答案:

没有答案