How could i convert this loop in python to a do while loop? for i in range(1,len
ID: 3729420 • Letter: H
Question
How could i convert this loop in python to a do while loop?
for i in range(1,len(df.columns)):
# skip over the discrete variables in coloumns 13-20
if i != outputVar and (i < 13 or i > 20):
testMax = np.corrcoef(df.iloc[:,i],df.iloc[:,outputVar])[0,1]
if abs(maxVal)-abs(testMax) < 0:
maxVal = testMax
maxIndex = i
for i in range(1,len(df.columns)):
# skip over the discrete variables in coloumns 13-20
if i != outputVar and (i < 13 or i > 20) and i != maxIndex:
testMax = np.corrcoef(df.iloc[:,i],df.iloc[:,outputVar])[0,1]
if abs(secondMaxVal)-abs(testMax) < 0:
secondMaxVal = testMax
secondMax = i
Explanation / Answer
i = 1 while True: # skip over the discrete variables in coloumns 13-20 if i != outputVar and (i < 13 or i > 20): testMax = np.corrcoef(df.iloc[:,i],df.iloc[:,outputVar])[0,1] if abs(maxVal)-abs(testMax) < 0: maxVal = testMax maxIndex = i if i == len(df.columns) - 1: break i = 1 while True: # skip over the discrete variables in coloumns 13-20 if i != outputVar and (i < 13 or i > 20) and i != maxIndex: testMax = np.corrcoef(df.iloc[:,i],df.iloc[:,outputVar])[0,1] if abs(secondMaxVal)-abs(testMax) < 0: secondMaxVal = testMax secondMax = i if i == len(df.columns) - 1: breakRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.