MCPcopy Create free account
hub / github.com/dask/dask / query

Method query

dask/dataframe/dask_expr/_collection.py:3639–3697  ·  view source on GitHub ↗

Filter dataframe with complex expression Blocked version of pd.DataFrame.query Parameters ---------- expr: str The query string to evaluate. You can refer to column names that are not valid Python variable names by surrounding the

(self, expr, **kwargs)

Source from the content-addressed store, hash-verified

3637 )
3638
3639 def query(self, expr, **kwargs):
3640 """Filter dataframe with complex expression
3641
3642 Blocked version of pd.DataFrame.query
3643
3644 Parameters
3645 ----------
3646 expr: str
3647 The query string to evaluate.
3648 You can refer to column names that are not valid Python variable names
3649 by surrounding them in backticks.
3650 Dask does not fully support referring to variables using the '@' character,
3651 use f-strings or the ``local_dict`` keyword argument instead.
3652
3653 See also
3654 --------
3655 pandas.DataFrame.query
3656 pandas.eval
3657
3658 Examples
3659 --------
3660 >>> import pandas as pd
3661 >>> import dask.dataframe as dd
3662 >>> df = pd.DataFrame({'x': [1, 2, 1, 2],
3663 ... 'y': [1, 2, 3, 4],
3664 ... 'z z': [4, 3, 2, 1]})
3665 >>> ddf = dd.from_pandas(df, npartitions=2)
3666
3667 Refer to column names directly:
3668
3669 >>> ddf.query('y > x').compute()
3670 x y z z
3671 2 1 3 2
3672 3 2 4 1
3673
3674 Refer to column name using backticks:
3675
3676 >>> ddf.query('`z z` > x').compute()
3677 x y z z
3678 0 1 1 4
3679 1 2 2 3
3680 2 1 3 2
3681
3682 Refer to variable name using f-strings:
3683
3684 >>> value = 1
3685 >>> ddf.query(f'x == {value}').compute()
3686 x y z z
3687 0 1 1 4
3688 2 1 3 2
3689
3690 Refer to variable name using ``local_dict``:
3691
3692 >>> ddf.query('x == @value', local_dict={"value": value}).compute()
3693 x y z z
3694 0 1 1 4
3695 2 1 3 2
3696 """

Callers 2

test_queryFunction · 0.95

Calls 2

new_collectionFunction · 0.90
QueryClass · 0.90

Tested by 2

test_queryFunction · 0.76