Applying group selection conditions using groupeddataframes

Here is another solution using the latest and best macro-tools, in one fell swoop

using Pipe, PairAsPipe, DataFramesMeta
df_result = @pipe df |>
    groupby(_, :id) |>
    combine(_,
        @pap(status1and2 = sum(in(1:2), :status)),
        @pap(not_wokring_age = sum(:status .== 1 .& (:age .< 25 .| :age .> 61)))
    ) |>
    @where(_, :status1and2 .== 2, :not_wokring_age .== 0) |>
    @select(_, :id) |>
    innerjoin(_, df; on = :id)
1 Like