[英]Grouping by two columns and add a third column based on a condition of two columns
[英]Get values of two different columns based on a condition in a third column
我有一个特定的条件( Incident = yes
),我想知道满足这个条件的两列中的值。 我有一个非常大的数据框(多行多列),我正在寻找“筛选”功能。
用df
来说明以下示例(列数比显示的多得多):
Repetition Step Incident Test1 Test2
1 1 no 10 20
1 1 no 9 11
1 2 yes 9 19
1 2 yes 11 20
1 2 yes 12 22
1 3 yes 9 18
1 3 yes 8 18
我想得到的答案是
Repetition Step
1 2
1 3
如果我只想知道 Step,我会使用以下命令:
df[df.Incident == 'yes'].Step.unique()
是否有类似的命令来获取特定条件下两列的值?
谢谢您的帮助! :-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.