大 pandas 获得两列的最小值作为方程式的一部分 [英] pandas get minimum value of two columns as part of an equation
问题描述
如何作为熊猫数据框方程的一部分引用两个数据框的最小值?我尝试使用无法正常工作的python min()
函数.很抱歉,如果在某处对此进行了详细记录,但我无法找到解决此问题的可行解决方案.我正在寻找与此类似的东西:
How can I reference the minimum value of two dataframes as part of a pandas dataframe equation? I tried using the python min()
function which did not work. I'm sorry if this is well-documented somewhere but I have not been able to find a working solution for this problem. I am looking for something along the lines of this:
data['eff'] = pd.DataFrame([data['flow_h'], data['flow_c']]).min() *Cp* (data[' Thi'] - data[' Tci'])
我还尝试了使用熊猫min()
函数,该函数也不起作用.
I also tried to use pandas min()
function, which is also not working.
min_flow = pd.DataFrame([data['flow_h'], data['flow_c']]).min()
InvalidIndexError: Reindexing only valid with uniquely valued Index objects
这个错误让我感到困惑.数据列只是数字和名称,我不确定索引在哪里起作用.
I was confused by this error. The data columns are just numbers and a name, I wasn't sure where the index comes into play.
In [108]: data['flow_c']
Out[108]:
0 74.014640
1 74.150579
2 74.014640
3 73.960195
4 74.069046
5 73.960195
6 73.987423
7 73.905710
推荐答案
您的问题对我来说不是很清楚,但是我的猜测是,您正在尝试获取两个Series
中的元素级mininum
(不是DataFrame
s).如果那是您想要的,请尝试:data[['flow_h','flow_c']].min(axis=1)
.
Your question is not very clear to me, but my guess is that you are trying to get element-wise mininum
of two Series
(not DataFrame
s). If that's what you want, try: data[['flow_h','flow_c']].min(axis=1)
.
这篇关于大 pandas 获得两列的最小值作为方程式的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!