pandas多个过滤行操作符

问题描述 投票:-2回答:1

我想在数据帧上应用多个行过滤器。以下是数据框的外观:

                        Issue Type                      Status      Orac
            0           Risk Event  Closed - Actions    Completed   Orac
            1           Conformance Testing             Open        Orac
            2           Risk Event                      Draft       Orac
            3           Risk Event                      Open        Orac
            4           Risk Event  Closed - Actions    Completed   Orac

这是我为数据帧制定的代码:

xl = pd.ExcelFile(file)

df = xl.parse('Detailed Issue List Report by O')


dfo = df({'Issue Type':['Lessons Learnt','Other Control Issues']},
     {'Status':['Open','Open - Actions Completed']})


df1 = dfo[['Issue Type', 'Status']]


df1['Orac'] = pd.Series('Orac', index=df1.index)

现在我想过滤('经验教训','其他问题','风险事件')和状态('打开','打开 - 操作已完成')中的问题类型

我收到了这个错误:第16行,在

 dfo = df({'Issue Type':['Lessons Learnt','Other Control Issues']})
          builtins.TypeError: 'DataFrame' object is not callable

在这条线上:

 dfo = df({'Issue Type':['Lessons Learnt','Other Control Issues']},
          {'Status':['Open','Open - Actions Completed']})

请协助。

非常感谢

python
1个回答
0
投票

使用名为pandas.loc方法轻松实现此目的:

issueLst = ['lesson learnt','other issues','risk event']
statusLst = ['Open','Open - Actions Completed']
df1 = df1.loc[df1['Issue Type'].isin(issueLst) & df1.loc[df1['Status'].isin(statusLst]

编辑:你的错误是因为你试图调用df(),这不是一个函数

© www.soinside.com 2019 - 2024. All rights reserved.