Alex Dowd
Alex Dowd

Reputation: 39

Create new pandas data frame based on 2 conditions in an existing column

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")]

Upvotes: 0

Views: 100

Answers (1)

Anurag Reddy
Anurag Reddy

Reputation: 1215

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().

Upvotes: 2

Related Questions