Reputation: 473
I have a dataframe (let's call it df) that looks a bit like this:
Offer | Cancelled | Restriction
------|-----------|------------
1 | N | A
2 | Y | B
3 | N | NaN
4 | Y | NaN
I have the following bit of code, which creates a list of all offers that have been cancelled:
cancelled = list('000'+df.loc[(df['Cancelled']=='Y'),'Offer'].astype(str))
What I now want to do is to adapt this to create a list of all offers where the 'Restriction' column is not NaN. So my desired result would look like this:
['0001','0002']
Does anyone know how to do this please?
Upvotes: 0
Views: 55
Reputation: 998
You were almost there. Just add the extra condition that the Restriction column may not be NaN.
list('000'+df.loc[(df['Restriction'].notna()) & (df['Cancelled'] == 'Y'), 'Offer'].astype(str))
If you just want to filter on not NaN in Restriction column, the answer is commented by @Henry Ecker
Upvotes: 1