w3resource

Pandas DataFrame: eval() function

DataFrame - eval() function

The eval() function evaluates a string describing operations on DataFrame columns.

Operates on columns only, not specific rows or elements. This allows eval to run arbitrary code, which can make you vulnerable to code injection if you pass user input to this function.

Syntax:

DataFrame.eval(self, expr, inplace=False, **kwargs)

Parameters:

Name Description Type/Default Value Required / Optional
expr  The expression string to evaluate. str Required
inplace  If the expression contains an assignment, whether to perform the operation inplace and mutate the existing DataFrame. Otherwise, a new DataFrame is returned. bool
Default Value: False
Required
kwargs   See the documentation for eval() for complete details on the keyword arguments accepted by query() dict  

Returns: ndarray, scalar, or pandas object
The result of the evaluation.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - diff() function
Next: DataFrame - max() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/pandas/dataframe/dataframe-eval.php