mercredi 10 juin 2020

pandas column not showing once created from if statement

I am trying to create a new column showing one of two values depending on if an IF statement is satisfied. I am receiving no errors when the code is ran, but the column is not showing up.

Code explained: If my column ['gap_size'] is less than or equal to 0, new column ['gap pos'] is false If my column ['gap_size'] is greater than or equal to 0, new column ['gap pos'] is true

Then, depending on if ['gap pos'] is true or false, and how ['Open2Close'] compares to ['gap size'] I want a new column ['gap filled?'] to be either 'filled', or 'not filled'

My problem is that the new column ['gap filled'] is not appearing when ran.

mgn.loc[mgn['gap_size'] <= 0, 'gap pos'] = False
mgn.loc[mgn['gap_size'] >= 0, 'gap pos'] = True

if (mgn['gap pos'] == True).all():
    mgn.loc[mgn['Open2Close'] <= -1* (mgn['gap_size']), 'gap filled?'] = 'Filled'
    mgn.loc[mgn['Open2Close'] > -1* (mgn['gap_size']), 'gap filled?'] = 'Not filled'

elif (mgn['gap pos'] == False).all():
    mgn.loc[mgn['Open2Close'] <= (mgn['gap_size']), 'gap filled?'] = 'Filled'
    mgn.loc[mgn['Open2Close'] >= (mgn['gap_size']), 'gap filled?'] = 'Not filled'


Aucun commentaire:

Enregistrer un commentaire