如何根据不断变化的考试状态从数据帧创建子集
我想知道如何根据具有相应 id 的患者的检查状态的变化(每个患者一个 id),从 python 中的数据帧创建子集
例如,如果某个 id 有 5 个检查(并且 exam_status可以是 1 或 0)我想仅基于更改检查状态(从 0 到 1)的患者创建一个新数据框。原始 df 有 72 列,所以它是就像原始版本的副本,但仅选择“exam_status”从 0 更改为 1 的副本
我知道如何根据最后的 exam_status 创建 df:
df = df.groupby("id").last()[list(df.groupby("id")["exam_status"].last() == 1)]
但我想要更改的那些!有人可以帮忙吗? 谢谢你!!
以下是 id 更改的示例: 示例
I would like to know how to create a subset from a dataframe in python, based on the changing of an exam status of a patient with a corresponding id (one id per patient)
For example, if a certain id has 5 exams (and exam_status can be 1 or 0) I would like to create a new dataframe based only on the patients that changed the exam status (from 0 to 1).The original df has 72 columns, so it's like a copy from the original but selecting only the ones where "exam_status" changed from 0 to 1
I know how to create a df based on the last exam_status:
df = df.groupby("id").last()[list(df.groupby("id")["exam_status"].last() == 1)]
But I want the ones who changed! Can someone help?
Thank you!!
here's an example of an id that changed:
example
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论