0

Easy question here: I am creating a new data frame based on a report of contracts where I only want 2 statuses. I have the first one, but am having trouble adding the second condition.

df2 = df[(df['[PCW] Contract Status'] == "Draft")]

The other status is "Draft Amendment". So I basically want it to read like

df2 = df[(df['[PCW] Contract Status'] == "Draft", "Draft Amendment")]
Alex Dowd
  • 39
  • 9
  • Does this answer your question? [How to filter Pandas dataframe using 'in' and 'not in' like in SQL](https://stackoverflow.com/questions/19960077/how-to-filter-pandas-dataframe-using-in-and-not-in-like-in-sql) – Bill Huang Oct 27 '20 at 15:34
  • are you trying to bring in only entries where the '[PWC] Contract Status' is 'Draft' or 'Draft Amendment'? If so, all you need should be: df[(df['[PCW] Contract Status'] == "Draft") or (df['[PCW] Contract Status'] == "Draft Amendment")] – houseofleft Oct 27 '20 at 15:35

1 Answers1

2

You can use isin().

df2 = df[df['[PCW] Contract Status'].isin(["Draft", "Draft Amendment"])]

Or else you can create the list of required variables earlier and then add the name of the list in isin().

Anurag Reddy
  • 1,159
  • 11
  • 19