I have a pandas dataframe that requires a lot of conditionals to calculate specific values and it is taking quite a lot of time to run. I was wondering if anyone could suggest a better way of handling this. The code is as follows:
for value in value_range:
del final_list[:]
if value>=340 and value<=640:
for time in df_1.index:
if (value >= 340 and value <= 360):
rad = band_correction_interpolation(360, df_2, time, st0[str(value)], ft0['value'])
final_list.append(rad)
elif (value > 360 and value < 380):
rad = interpolation(df_1, df_2, value, 360, 380, time, st0, ft0)
final_list.append(rad)
elif (value > 380 and value <= 410):
if value == 410:
rad = interpolation(df_1, df_2, value, 380, 440, time, st0, ft0)
else:
rad = interpolation(df_1, df_2, value, 380,410, time, st0, ft0)
final_list.append(rad)
df_final[str(value)] = final_list
elif (value > 640 and value<= 2500):
for time in df_1.index:
if (value > 640 and value < 840):
rad = interpolation(df_1, df_2, value, 640, 840, time, st0, ft0)
final_list.append(rad)
elif (value >= 840 and value <= 1000):
rad = band_correction_interpolation(840, df_2, time, st0[str(value)], ft0['value'])
final_list.append(rad)
elif (value >= 1640 and value <=2500):
rad = band_correction_interpolation(1640, df_2, time, st0[str(value)], ft0['value'])
final_list.append(rad)
df_final[str(value)] = final_list
Unfortunately, this is part of a bigger program and it wouldn't really make sense to show an output or the input data. The gist of it is that, I need to apply mathematical calculations with different parameters based on what is in 'value'.