我正在尝试创建一个新的df作为现有df的子集,使用:
filtered_df = df[((df.col == "Developing") | (df.col == "Ineffective") & (df.col_16 == "Developing") | (df.col_16== "Ineffective"))]
但这只是返回现有的df,没有应用任何过滤。在
我也试过:
^{pr2}$另外,我还尝试分别为or
和{|
和{|
或{
返回相同的结果
我的数据通常如下:
ID loc col col_16 col_17 col_18
4568 12P Effective Ineffective Effective Developing
8521 02F Ineffective Developing Effective Highly Effective
期望的输出是df的过滤版本,其中只满足我指定的条件(col和col_16都表示“正在开发”或“无效”)。对于示例数据,只返回第二行。在
您可以使用
loc
来分割数据。假设您的原始数据集与您列出的数据集相同,并且存储为df
,那么首先创建一个包含要过滤的单词的列表。在有关使用
loc
和位于here的其他数据帧切片器的文档。在您似乎缺少了一组将or语句分组在一起的括号:
试试这个:
相关问题 更多 >
编程相关推荐