简体   繁体   English

如何在 Excel 中读取公式并将其转换为在 Python 中进行计算?

[英]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.

相关问题 如何有效地从大型excel文件中读取数据,进行计算,然后将结果存储回python中? - How to efficiently read data from a large excel file, do the computation and then store results back in python? 如何重新创建一个在Python中调用TREND()的Excel公式? - How do I recreate an Excel formula which calls TREND() in Python? 我如何在运行时从excel读取到python中? - How do i read from excel into python at runtime? 如何将 excel 文件转换为嵌套的 python 字典? - How do I convert an excel file into a nested python dictionary? 如何在 Python 中读取 Excel 格式的日期? - How do I read a date in Excel format in Python? 我如何告诉 python 整个值是一个字符串? 因为我的 excel 公式中有撇号 - How do I tell python the whole value is a string? since my excel formula has apostrophe in it 如何使用 python 向下多行迭代 excel 公式 - how do I iterate an excel formula down multiple rows using python 如何在python中进行浮点计算? - How to do floating point computation in python? 如何在精确指定cpu的Python上执行并行计算否我要做任务i? - How to do a parallel computation on Python exactly specifying cpu no i do task i? 如何将Excel公式应用于整个列中的值? - How do I apply an Excel formula to the values in an entire column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM