lundi 2 août 2021

Putting multiple if statments in one if statment in python pandas

I need to convert this big if statement from python to python pandas. I have a problem because inside of this statement have a multiple if statements.

All values (x_value, i_value, u_value, y_val, tb, uvd) are columns in xlsx sheet. I need to create a new column with codes that are in print function. Statement is a longer than is showed here

import math

if x_value <= 1.00 and x_value >= 0:
    if y_val <= 0.25 and y_val >= 0:
        if tb < 0 and i_value == 0:
            print('aa1')
        elif tb < 0 and uvd > 0:
            print('aa2')
        elif tb < 0 and uvd < 0:
            print('aa3')
        elif tb > 0 and uvd < 0:
            print('aa4')
        elif tb > 0 and uvd > 0:
            print('aa5')
        elif tb > 0 and u_value > 0:
            print('aa6')
        else:
            print('error')
    elif y_val <= 0.50 and y_val >= 0.25:
        if tb < 0 and i_value == 0:
            print('ab1')
        elif tb < 0 and uvd > 0:
            print('ab2')
        elif tb < 0 and uvd < 0:
            print('ab3')
        elif tb > 0 and uvd < 0:
            print('ab4')
        elif tb > 0 and uvd > 0:
            print('ab5')
        elif tb > 0 and u_value > 0:
            print('ab6')
        else:
            print('error')
    elif y_val <= 0.75 and y_val >= 0.50:
        if tb < 0 and i_value == 0:
            print('ac1')
        elif tb < 0 and uvd > 0:
            print('ac2')
        elif tb < 0 and uvd < 0:
            print('ac3')
        elif tb > 0 and uvd < 0:
            print('ac4')
        elif tb > 0 and uvd > 0:
            print('ac5')
        elif tb > 0 and u_value > 0:
            print('ac6')
        else:
            print('error')
    elif y_val <= 1.00 and y_val >= 0.75:
        if tb < 0 and i_value == 0:
            print('ad1')
        elif tb < 0 and uvd > 0:
            print('ad2')
        elif tb < 0 and uvd < 0:
            print('ad3')
        elif tb > 0 and uvd < 0:
            print('ad4')
        elif tb > 0 and uvd > 0:
            print('ad5')
        elif tb > 0 and u_value > 0:
            print('ad6')
        else:
            print('error')
    else:
        print('Error!')

elif x_value <= 3.00 and x_value >= 1:
    if y_val <= 0.25 and y_val >= 0:
        if tb < 0 and i_value == 0:
            print('ba1')
        elif tb < 0 and uvd > 0:
            print('ba2')
        elif tb < 0 and uvd < 0:
            print('ba3')
        elif tb > 0 and uvd < 0:
            print('ba4')
        elif tb > 0 and uvd > 0:
            print('ba5')
        elif tb > 0 and u_value > 0:
            print('ba6')
        else:
            print('error')
    elif y_val <= 0.50 and y_val >= 0.25:
        if tb < 0 and i_value == 0:
            print('bb1')
        elif tb < 0 and uvd > 0:
            print('bb2')
        elif tb < 0 and uvd < 0:
            print('bb3')
        elif tb > 0 and uvd < 0:
            print('bb4')
        elif tb > 0 and uvd > 0:
            print('bb5')
        elif tb > 0 and u_value > 0:
            print('bb6')
        else:
            print('error')
    elif y_val <= 0.75 and y_val >= 0.50:
        if tb < 0 and i_value == 0:
            print('bc1')
        elif tb < 0 and uvd > 0:
            print('bc2')
        elif tb < 0 and uvd < 0:
            print('bc3')
        elif tb > 0 and uvd < 0:
            print('bc4')
        elif tb > 0 and uvd > 0:
            print('bc5')
        elif tb > 0 and u_value > 0:
            print('bc6')
        else:
            print('error')
    elif y_val <= 1.00 and y_val >= 0.75:
        if tb < 0 and i_value == 0:
            print('bd1')
        elif tb < 0 and uvd > 0:
            print('bd2')
        elif tb < 0 and uvd < 0:
            print('bd3')
        elif tb > 0 and uvd < 0:
            print('bd4')
        elif tb > 0 and uvd > 0:
            print('bd5')
        elif tb > 0 and u_value > 0:
            print('bd6')
        else:
            print('error')
    else:
        print('Error!')
else:
    print('ERROR')

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire