bodo.pandas.BodoDataFrame.query¶
BodoDataFrame.query(expr, *, parser="pandas", engine=None, local_dict=None, global_dict=None, resolvers=None, level=0, inplace=False)
Parameters
-
expr: str: The query string to evaluate.
-
local_dict dict | None, default None: A dictionary of local variables, taken from stack locals by default.
-
global_dict dict | None, default None: A dictionary of global variables, taken from stack globals by default.
-
resolvers: list-like of dict-like | None, default None: An additional list of maps between names and their respective values to use for variable lookup while parsing
expr. The providedresolverswill be added to the resolvers used internally to inject theBodoDataFrame.indexandBodoDataFrame.columnsvariables that refer to their respective BodoDataFrame instance attributes. -
level: int, default 0: The number of prior stack frames to traverse and add to the current scope. Most users will not need to change this parameter (unless passing an unsupported argument; see below).
-
Setting the
parser,engine, orinplaceparameters to a value other than the default will trigger a fallback topandas.DataFrame.query. In such a case, if using variable references inexpr, either thelevelparameter must be incremented or alocal_dict/global_dictmust be provided explicitly. Returns
-
BodoDataFrame
Notes
For more details on supported operations, functions, and formatting in the query string expr, see the pandas documentation at pandas.DataFrame.query.
Examples
import bodo.pandas as bd
bdf = bd.DataFrame(
{
"A": [1, 3, 5, 7, 9],
"B B": [0.6, 3.2, 0.19, 0.18, 7.4],
"C&C": ["DD", "EEE", "F", "EE", "E"]
}
)
bdf_queried1 = bdf.query("ceil(`B B`) == A or (A > `B B` and `C&C`.str.contains('EE'))")
print(bdf_queried1)
Output:
list_var = [3.2, 0.18, 2, 10.1, 5]
bdf_queried2 = bdf.query("A in @list_var & not (`B B` == @list_var | `C&C`.str.len() > @length)", local_dict={"length": 1})
print(bdf_queried2)
Output: