[英]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.这里有一个简单的问题:我正在根据合同报告创建一个新的数据框,我只需要 2 个状态。 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")]
You can use isin()
.您可以使用
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()
.或者您可以更早地创建所需变量的列表,然后在
isin()
中添加列表的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.