如何找到每个学生人数都属于独特的学生?

发布于 2025-01-31 03:40:25 字数 165 浏览 6 评论 0原文

我有一个数据框架和约10-12列。该列之一是学生编号,例如1234567,另一个是标识符,例如护照号码,许可证号。我如何发现每个学生都有一个唯一的标识符。像学生1234567一样,仅具有标识符ABC5679K。我也想存储用重复标识符标记的学生。例如,如果学生1234567也具有标识符ABC3408T,我想知道这些。

I have a data frame and around 10-12 columns. One of the column is the student number e.g. 1234567 and the other is an identifier e.g passport numbers, license number . How can I find that each student has a unique identifier. Like student 1234567 has identifier ABC5679K only. Also I want to store the students who are tagged with duplicate identifier. For e.g. If student 1234567 also has identifier ABC3408T, I want to know those.

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

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

发布评论

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

评论(2

满身野味 2025-02-07 03:40:25

假设第一个学生具有唯一的其他ID,而第二个则具有两个不同的ID:

   student_id other_id
0           1        a
1           1        a
2           2        b
3           2        c

groupby.transform nunique nunique 为此

mask = df.groupby('student_id')['other_id'].transform('nunique').gt(1)

print(df[mask])

   student_id other_id
2           2        b
3           2        c

您可以使用,对于所有具有重复其他ID的学生的列表:

s = df.groupby('student_id')['other_id'].nunique()
s[s>1].index.to_list()

输出:[2]

Assuming such input, where the first student has a unique other id, while the second has two different ids:

   student_id other_id
0           1        a
1           1        a
2           2        b
3           2        c

you can use GroupBy.transform with nunique for that:

mask = df.groupby('student_id')['other_id'].transform('nunique').gt(1)

print(df[mask])

output:

   student_id other_id
2           2        b
3           2        c

Or, for a list of all students with duplicated other ids:

s = df.groupby('student_id')['other_id'].nunique()
s[s>1].index.to_list()

output: [2]

枫林﹌晚霞¤ 2025-02-07 03:40:25

df.groupby([“ student_name”])[“ passport_number”]。nunique()> 1

您可以使用GroupBy和Nunique功能来帮助您识别重复序列。希望这个回答您的问题。

df.groupby(["student_name"])["passport_number"].nunique() > 1

You can use the groupby and nunique function to help you identify repeats. Hope this answer your question.

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