Query data when using dask-awkward #1283
-
Dear experts, I'm a starter on uproot.dask. I'm trying to apply some selections on data using it. Is there a way to apply selections to Dask-Awkward similar to Dask.dataframe.query? Something like https://docs.dask.org/en/stable/generated/dask.dataframe.DataFrame.query.html Thanks, |
Beta Was this translation helpful? Give feedback.
Answered by
jpivarski
Aug 30, 2024
Replies: 1 comment 4 replies
-
Yes, here's an example (given the array from here): >>> import awkward as ak
>>> import dask_awkward as dak
>>> array = ak.Array([
... [{"x": 1.1, "y": [1]}, {"x": 2.2, "y": [1, 2]}, {"x": 3.3, "y": [1, 2, 3]}],
... [],
... [{"x": 4.4, "y": [1, 2, 3, 4]}, {"x": 5.5, "y": [1, 2, 3, 4, 5]}]
... ])
>>> delayed_array = dak.from_awkward(array, npartitions=1)
>>> selected_delayed_array = delayed_array[delayed_array.x > 3]
>>> selected_delayed_array.compute().show()
[[{x: 3.3, y: [1, 2, 3]}],
[],
[{x: 4.4, y: [1, 2, 3, 4]}, {x: 5.5, y: [1, ..., 5]}]] Only the records in which |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Each
delayed_array.x > 3
anddelayed_array.y > 1
creates an array of booleans that can be used as a slice. To combine the two arrays of booleans with "and", use the bitwise operator&
(with parentheses for correct order-of-operations):