Is it possible to convert the for loop with an if-condition, in the given code, to a list comprehension?
ListIndex = 0
timeSeries = []
Value = defaultValue
dfLength = len(dfCont.index)
for i in range(dfLength):
if abs(dfCont.iloc[i, 0] - occurance[ListIndex]) < 0.0001:
Value = discreteValues[ListIndex]
ListIndex = ListIndex + 1
timeSeries.append(Value)
I tried using standard definition to compress this for loop into list comprehension but it doesn't seem to work. Would it be possible to convert this for-loop into a list comprehension in the first place? And if yes, what is the best way to do it?