[英]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.数据通过 Pandas 读入 Python 并转换为数据帧。
Next, I need to read in from an Excel file, the formula I need to use for computation for Table 1.接下来,我需要从 Excel 文件中读取用于计算表 1 的公式。
Eg in the Excel file, the listed formula for Table 1 is "=sum(Jan 1999: Dec 1999)"例如,在 Excel 文件中,表 1 列出的公式为“=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? Python 代码有没有办法知道如何解释这个公式并对表 1 中的每一行进行计算?
So the result for Table 1: Peter=12,000;所以表1的结果:Peter=12,000; John=12,000
约翰=12,000
Thank you谢谢
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.似乎模块
formulas
适合您尝试执行的操作,允许解析和计算 Excel 公式,而无需再次打开 Excel。
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.我没有深入了解这个库,所以也许使用过它的人可以用一个实际的代码片段来补充我的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.