- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想根据特定列“ContactID”对该 DataFrame 进行分组,但如果该组的列“PaymentType”不包含特定值,那么我想从 DataFrame 中删除整个组。
我有这样的东西:
UniqueID = data.drop_duplicates('ContactID')['ContactID'].tolist()
OnlyRefinance=[]
for i in UniqueID:
splits = data[data['ContactID']==i].reset_index(drop=True)
if any(splits['PaymentType']==160):
OnlyRefinance.append(splits)
OnlyRefinance = pd.concat(OnlyRefinance)
这可行,但速度非常慢,我想知道是否有更快的方法来完成此任务。
最佳答案
您可以使用 groupby.filter
的另一个选项:
data.groupby("ContactID").filter(lambda g: (g.PaymentType == 160).any())
这只会保留 PaymentType 包含 160 的组。
关于 python Pandas : Is There a Faster Way to Split and Recombine a DataFrame based on criteria?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42095584/
我有一些数据代表许多不同站点的及时结果。我想找到我的结果的四分位分解以及每个站点的最大和最小日期。 找到其中的每一个都非常容易: #quartiles q = df.groupby(['site_id
我正在R中进行经典的拆分应用重组操作。随着时间的推移,我的数据集是一堆公司。我正在做的应用程序是对每个公司进行回归并返回残差,因此,我未按公司进行汇总。 plyr对此非常有用,但是当公司数量很大时,它
我正在尝试按天汇总我的数据,以便将其呈现在图表中。通过按$year、$month 和$dayOfMonth 分组,我成功地做到了这一点。但是,这意味着我的日期现在在最终结果中分为三个部分。有没有办法将
我想根据特定列“ContactID”对该 DataFrame 进行分组,但如果该组的列“PaymentType”不包含特定值,那么我想从 DataFrame 中删除整个组。 我有这样的东西: Uniq
我是一名优秀的程序员,十分优秀!