Apologies for the butchered title.
I have a db of metrics where I have fields like Metric Title, Metric ID, Metric Abbreviation, and Metric Formula. The Metric Formula indicates if the metric requires other metrics to be calculated. For example:
| Metric Title | Metric ID | Metric Abbreviation | Metric Formula |
|---|---|---|---|
| MetricA | 234 | MA | |
| MetricB | 567 | MB | |
| MetricC | 452 | MC | MA+MB |
| MetricD | 123 | MD | MC*MA |
I am trying to implement a recursive function that evaluates if the metric formula is not empty to use the abbreviations in the formula to then evaluate those row's formula field and so on and so on. Once it's at the root node, ie a row where the metric formula is empty get a value and go back up one level. Could someone please point me in the right direction for researching this type of algorithm?
If I understand correctly and you want to evaluate the formulas, you could take advantage of
pandas.eval. Build a dictionary of abbreviations:ID, and pass it toevalas alocal_dict:Output: