Pandas DataFrame - ' bool'对象不可订阅

发布于 2025-02-09 05:34:14 字数 420 浏览 2 评论 0原文

我正在尝试在数据框架中检索记录,该记录在单独的列表中没有匹配的ID。本质上,我想从dataframe中删除唯一ID匹配列表pm_docids中的任何ID的任何记录:

df = df[~df['UniqueId']].isin((PM_docIDs).index, inplace=True)

这会产生以下错误:

In  [35]:
Line 4:     df = df[~df['UniqueId']].isin((PM_docIDs).index, inplace=True)

TypeError: 'bool' object is not subscriptable

是否有一种更轻松的方法来执行此操作,或者我可以做些什么来修复摘要Aboveso我不喜欢的摘要。 t获得typeError?

I am trying to retrieve records in a dataframe that do not have matching IDs in a separate list. Essentially, I want to drop any records from the dataframe where UniqueId matches any Ids in the list PM_docIDs:

df = df[~df['UniqueId']].isin((PM_docIDs).index, inplace=True)

This produces the following error:

In  [35]:
Line 4:     df = df[~df['UniqueId']].isin((PM_docIDs).index, inplace=True)

TypeError: 'bool' object is not subscriptable

Is there an easier way to do this or is there something I can do to fix the snippet aboveso I don't get the TypeError?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情泪▽动烟 2025-02-16 05:34:14

您很亲密,但是您的语法有些混乱。怎么样?

df = df[~df['UniqueId'].isin(PM_docIDs.index)]

You're close, but your syntax is a little jumbled. How about this?

df = df[~df['UniqueId'].isin(PM_docIDs.index)]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文