1

I want to build an expression and evaluate it in python. Basically I will have Rule ID for which I need to build a Trigger condition (T), LHS (L), RHS (R) in the form of expression.

All the data required to build the above 3 expression will be stored in a form of three tables in database. Let say,

1) Constant table - stores rule Id and constants along with their order

2) Operator table - stores rule Id and operators, prior operator along with their order

3) Variable table - stores rule Id and variables, prior operator along with their order

Tables data will be in form of

enter image description here

so based on the equation order id, I need to build T, L, R expression for the given RuleId. For example: expression for the RuleId =3, T,L,R will be as follows

T : ( ! 2204) and ( ! 2204)

L : 2204

R : 2204 * 2.00000

Tried by building the expressions using stack, queue in C#, it worked fine. Is there any other easy way exists in python to achieve this?

1 Answers1

0

Had a very similar issue and cs95's solution on the related post worked for me:

Dynamically filtering a pandas dataframe

Basically, string parsing + eval() looks like a good option, or df.query() if you're using pandas already.