pandas 计算熊猫的力量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16083499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:46:27  来源:igfitidea点击:

Calculating power in pandas

pythonpandas

提问by chandradog

Using python 2.7.3 and pandas 0.10.1, I am getting a deprecation warning when I try to use the ** operation to calculate power (mathematical, not thermodynamic). In the documentation, it covers the use of add, sub, mul, and div for Series and DataFrame arithmetic operations. However, I cannot find anything covering ** for these, as in 3 ** 2 = 9. What can I do besides use ** and hope for the best?

使用 python 2.7.3 和 pandas 0.10.1,当我尝试使用 ** 操作来计算功率(数学,而不是热力学)时,我收到了弃用警告。在文档中,它涵盖了对 Series 和 DataFrame 算术运算使用 add、sub、mul 和 div。但是,我找不到任何涵盖 ** 的内容,例如 3 ** 2 = 9。除了使用 ** 并希望最好之外我还能做什么?

回答by Pace

To calculate exponentiation between a time series and a data frame one should do:

要计算时间序列和数据帧之间的幂,应该执行以下操作:

dataFrame.pow(timeSeries, axis=0)

To calculate exponentiation between a series and a scalar one can still do:

要计算一个系列和一个标量之间的幂,仍然可以这样做:

timeSeries ** exponent