Stream: helpdesk (published)

Topic: Logical index DataFrames.jl


view this post on Zulip Dale Black (Feb 15 2021 at 04:38):

Is there a simple way to logically index a DataFrame?

For example, if I want to keep every row that has a 1 and discard every row that has a 0 in the column x

df[:, :x] .== 1

This returns a BitArray of Bool how would I use this BitArray to filter the entire DataFrame?

view this post on Zulip Dale Black (Feb 15 2021 at 04:41):

This seems to work!

filter(:x => isequal(1), df)

view this post on Zulip Nils (Feb 15 2021 at 09:14):

Yes, that's the way - there's also the in-place version filter!, and @view df[df.x .== 1, :]


Last updated: Dec 28 2024 at 04:38 UTC