I have a dataframe type are:
FiscalYear int64
GL object
GLID int64
GL_Debit float64
GL_Credit float64
month object
diffDebit float64
diffCredit float64
diffval float64
I try to modify a float column (diffvalue) to multiply it on a condition My code is:
df['diffval'] = df.apply(lambda x: x['diffval']*-1 if x['GL'].str[0] in ['4','0'] else x['diffval'])
Im trying to do this but I have an error:
KeyError: ('GL', 'occurred at index FiscalYear')
dataframe sample :
[![enter image description here][1]][1] thanks
FiscalYear GL GLID GL_Debit GL_Credit month diffDebit diffCredit diffval
2020 1001 Banque:RBC 06621-1006014 (Salle Privée) 70 19386,69 0 2020-01-01 19386,69 0 19386,69
2020 1001 Banque:RBC 06621-1006014 (Salle Privée) 70 0 5074,84 2020-02-01 -19386,69 5074,84 -24461,53
2020 1002 Banque:Desjardins 0282527 (Traiteurs) 71 2758,45 0 2020-01-01 2758,45 0 2758,45
2020 1002 Banque:Desjardins 0282527 (Traiteurs) 71 2765,64 0 2020-02-01 7,19 0 7,19
2020 1003 Banque:Desjardins 0282857 (ED) 54 36725,91 0 2020-01-01 36725,91 0 36725,91
2020 1003 Banque:Desjardins 0282857 (ED) 54 117149,35 0 2020-02-01 80423,44 0 80423,44
2020 1004 Banque:RBC 05261-1020403 231 30282,34 0 2020-01-01 30282,34 0 30282,34
2020 1004 Banque:RBC 05261-1020403 231 2277,34 0 2020-02-01 -28005 0 -28005
2020 1061 Dépôt Stripe à recevoir:Stripe - Salle Privée 219 7208,32 0 2020-01-01 7208,32 0 7208,32
2020 1061 Dépôt Stripe à recevoir:Stripe - Salle Privée 219 6015,4 0 2020-02-01 -1192,92 0 -1192,92
2020 1062 Dépôt Stripe à recevoir:Stripe - Traiteurs.Co 220 1643,28 0 2020-01-01 1643,28 0 1643,28
2020 1062 Dépôt Stripe à recevoir:Stripe - Traiteurs.Co 220 2678,28 0 2020-02-01 1035 0 1035
2020 1099 Fonds non déposés 8 1200 0 2020-01-01 1200 0 1200
2020 1099 Fonds non déposés 8 0 0 2020-02-01 -1200 0 -1200
2020 1100 Compte clients (C/C) 74 65665,57 0 2020-01-01 65665,57 0 65665,57
2020 1100 Compte clients (C/C) 74 94235,09 0 2020-02-01 28569,52 0 28569,52
2020 1300 Actif du stock 68 0 0 2020-01-01 0 0 0
2020 1300 Actif du stock 68 0 0 2020-02-01 0 0 0
xis, it doesn't have a'GL'key. I wonder how we are supposed to find the problem when we don't know the contents of the DataFrame - at least a minimal example of it - minimal reproducible example