Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame eval() Method

❮ DataFrame Reference


Calculate the sum of two columns:

import pandas as pd

data = {
  "Women": [125, 230, 412],
  "Men": [219, 185, 452]

df = pd.DataFrame(data)

print(df.eval("Women + Men"))
Try it Yourself »

Definition and Usage

The eval() method evaluates the string expression and returns the result.

You can refer to specific columns by specifying the column label(s).


dataframe.eval(expr, inplace, kwargs)


The inplace parameter is a keyword argument.

Parameter Value Description
expr   Required. The string evaluate
inplace True
Optional, default False. Set to True if you want to perform the evaluation on the existing DataFrame instead of returning a new one.

 Return Value

A pandas object with the evaluated result.

❮ DataFrame Reference