pandas.eval(expr, parser='pandas', engine=None, truediv=True, local_dict=None, global_dict=None, resolvers=(), level=0, target=None, inplace=None)
Evaluate a Python expression as a string using various backends.
The following arithmetic operations are supported: +
, -
, *
, /
, **
, %
, //
(python engine only) along with the following boolean operations: |
(or), &
(and), and ~
(not). Additionally, the 'pandas'
parser allows the use of and
, or
, and not
with the same semantics as the corresponding bitwise operators. Series
and DataFrame
objects are supported and behave as they would with plain ol’ Python evaluation.
Parameters: |
expr : str or unicode The expression to evaluate. This string cannot contain any Python statements, only Python expressions. parser : string, default ‘pandas’, {‘pandas’, ‘python’} The parser to use to construct the syntax tree from the expression. The default of engine : string or None, default ‘numexpr’, {‘python’, ‘numexpr’} The engine used to evaluate the expression. Supported engines are
More backends may be available in the future. truediv : bool, optional Whether to use true division, like in Python >= 3 local_dict : dict or None, optional A dictionary of local variables, taken from locals() by default. global_dict : dict or None, optional A dictionary of global variables, taken from globals() by default. resolvers : list of dict-like or None, optional A list of objects implementing the level : int, optional The number of prior stack frames to traverse and add to the current scope. Most users will not need to change this parameter. target : a target object for assignment, optional, default is None essentially this is a passed in resolver inplace : bool, default True If expression mutates, whether to modify object inplace or return copy with mutation. WARNING: inplace=None currently falls back to to True, but in a future version, will default to False. Use inplace=True explicitly rather than relying on the default. |
---|---|
Returns: |
ndarray, numeric scalar, DataFrame, Series |
See also
The dtype
of any objects involved in an arithmetic %
operation are recursively cast to float64
.
See the enhancing performance documentation for more details.
© 2011–2012 Lambda Foundry, Inc. and PyData Development Team
© 2008–2011 AQR Capital Management, LLC
© 2008–2014 the pandas development team
Licensed under the 3-clause BSD License.
http://pandas.pydata.org/pandas-docs/version/0.18.1/generated/pandas.eval.html