Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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: break
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote