Starting from a df like that:
| Lev. | Qta | Text | Qty |
|---|---|---|---|
| .1 | 1 | Model3 | 1 |
| .2 | 2 | Gruoup1 | 1 |
| .3 | 5 | Gruoup1.1 | 4 |
| .3 | 1 | Gruoup1.2 | 1 |
| .3 | 2 | Gruoup1.3 | 1 |
| .3 | 1 | Gruoup1.4 | |
| .3 | 1 | Gruoup1.5 |
I want to create a new column comparing two different columns, for do this I defined a function like this:
def F1(k):
if (k['Lev'] == '.1'):
return 'Expl1'
elif (k['Lev'] == '.2'):
return 'Expl2'
elif (k['Qtà'] == k['Qty']):
return 'OK'
elif (k['Qtà'] > k['Qty']):
return 'NOK'
elif (k['Qtà'] < k['Qty']):
return 'Less'
elif (k['Qty'] is empty):
return'NoMap'
else
Return 'Check'
df['OK/NOK'] = df.apply(F1, axis=1)
The function works well except when in QTY I have an empty cell. When the cell is empty i receive 'Check' answer.
This is an example of what would like to obtain:
| Lev. | Qta | Text | Qty | OK/NOK. |
|---|---|---|---|---|
| .1 | 1 | Model3 | 1 | Expl1 |
| .2 | 2 | Gruoup1 | 1 | Expl2. |
| .3 | 5 | Gruoup1.1 | 4 | Less. |
| .3 | 1 | Gruoup1.2 | 1 | OK. |
| .3 | 2 | Gruoup1.3 | 1 | NOK. |
| .3 | 1 | Gruoup1.4 | NoMap. | |
| .3 | 1 | Gruoup1.5 | NoMap. |