Skip to content
Advertisement

Calling round(), ceiling(), floor(), min(), max() in pandas eval

As title says, Is there a way to support round, ceiling, min, max, floor functions in pandas eval.

DataFrame:

JavaScript

abs() and sqrt() function works with pandas eval. i.e.

JavaScript

can anyone suggest how to access rest of the functions in eval? I also tried ‘local_dict’ in eval to see if I can define custom functions and call them but it didn’t work.

Note:

  1. Arithmetic operations inside these functions are necessary (i.e. sum, multiplication, div of two columns).
  2. I am aware of issues around usage of ‘eval’ functions and taking necessary measurements.

Advertisement

Answer

With the help of ‘py_expression_eval’ libary, I was able to work out arithmatic operations inside user defined functions.

JavaScript

library source: https://github.com/Axiacore/py-expression-eval

Hope this helps others.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement