jeudi 1 février 2018

multiple if else conditions in pandas dataframe and derive multiple columns

I have a dataframe like below.

import pandas as pd
import numpy as np
raw_data = {'student':['A','B','C','D','E'],
        'score': [100, 96, 80, 105,156], 
    'height': [7, 4,9,5,3],
    'trigger1' : [84,95,15,78,16],
    'trigger2' : [99,110,30,93,31],
    'trigger3' : [114,125,45,108,46]}

df2 = pd.DataFrame(raw_data, columns = ['student','score', 'height','trigger1','trigger2','trigger3'])

print(df2)

I need to derive 3 new columns based on multiple conditions.

i need to compare score and height columns with trigger 1 -3 columns.

Flag Column:

Score greater than equal trigger 1 and height less than 8 then Red -- Score greater than equal trigger 2 and height less than 8 then Yellow -- Score greater than equal trigger 3 and height less than 8 then Orange -- if not satisfied blank

Text 1 and Text 2 columns is based on the trigger numbers we took. please look the output picture you can understand easily.

How to write if else conditions in pandas dataframe and derive multiple columns?

Wante Output

Thanks

Aucun commentaire:

Enregistrer un commentaire