Peter
Peter

Reputation: 383

How do I read in a Formula in Excel and convert it to do the computation in Python?

I have a table of time-series data downloaded from some system. Say it is the revenue data for different persons across time. Eg below

**Table 1**
|      | Jan 1999| Feb 1999|Dec 1999|
|----- | --------| --------|--------|
| Peter| 9000    | 2000    |1000    |
| John | 6000    | 1000    |5000    |

The data is read into Python via pandas and converted into a dataframe.

Next, I need to read in from an Excel file, the formula I need to use for computation for Table 1.

Eg in the Excel file, the listed formula for Table 1 is "=sum(Jan 1999: Dec 1999)"

Is there a way for Python code to know how to interpret this formula and do the computation for each row in Table 1?

So the result for Table 1: Peter=12,000; John=12,000

Thank you

Upvotes: 0

Views: 64

Answers (1)

Dario_Moed
Dario_Moed

Reputation: 11

It seems like the module formulas would be appropriate for what you're trying to do, allowing to parse and compute Excel formulas without having to open Excel all over again.

I did not dig deep into understanding the library, so maybe someone who has used it can complement my answer with an actual code snippet.

Upvotes: 1

Related Questions