Skip to content
Advertisement

select first occurrence where column value is greater than x for each A(key) | dataframe

What I have

JavaScript

What I want, select first occurrence where D >= 4 for each A(key)

So end result will look like,

JavaScript

Advertisement

Answer

You can first slice the rows that match the condition on D, then groupby A and get the first element of each group:

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement