如何不使用for循环来解决此问题? (蟒蛇)

时间:2019-12-11 11:51:16

标签: python for-loop time

我试图在python中解决以下问题,但由于数据库很大(.csv,100.000行),因此需要花费很多时间。 我怎样才能使其更快?

for i in range(len(df)):
if (df["time_choice"][i] < 0.125):
    df["time_choice2"][i] = 1/12
elif (df["time_choice"][i] > 0.125) and (df["time_choice"][i] < 75/125):
    df["time_choice2"]= 1/4
elif (df["time_choice"][i] > 75/125) and  (df["time_choice"][i] < 1.5):
    df["time_choice2"][i] = 1
elif (df["time_choice"] [i]> 1.5) and (df["time_choice"][i] < 2.5) :
    df["time_choice2"][i] = 2
elif (df["time_choice"][i] > 2.5) and  (df["time_choice"][i] < 4) :
    df["time_choice2"][i] = 3
elif (df["time_choice"][i] > 4) and  (df["time_choice"][i] < 7.5) :
    df["time_choice2"][i] = 5
elif (df["time_choice"][i] > 7.5):
    df["time_choice2"][i] = 10

0 个答案:

没有答案