'Optimizing Python code with 2D array, nested for loop and if conditions

Is there any way to improve the performance of below python code. I tried list comprehension, but not sure how to implement it on below scenario. *In below code, intcons is a dataframe

    p = [[0 for i in range(30)] for j in range(5)]
    violate = [[ 0 for i in range(8)] for j in range(4)]
    mm = []

    intcons['first.store_id'] = ((intcons.store_id != intcons.store_id.shift()))
    for i in intcons.index:
        if intcons['first.store_id'][i] == True:
            addit = 1
            for q in range(1, 6):
                intcons[f'f{q}'] = 0
                p[1][q] = 0
                p[3][q] = 0
            mm[1] = 1
            mm[2] = np.log(intcons['K1'])
            mm[3] = np.log(intcons['K2'])    
            mm[4] = np.log(intcons['K3'])
            mm[5] = np.log(intcons['K4'])
            intercep = 1
    
            for er in range(6, 10):
                for j in range(1, 5):
                    p[er][j] = 0
                    if er == j + 5:
                        p[er][j] = 1
            for hh in range(1, 4):
                for z in range(1, 2):
                    violate[hh][z] = 0
                    print(i)
        else:
            addit = addit + 1


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source