我正在尝试使用系数在数据中创建一个新列。
(这些系数的计算方法是通过函数f_coef
和v_coef
)
最后,我尝试了两种不同的方法,但是没有一种起作用。
我不知道如何解决它,我已经找了一段时间,但没有找到答案。
错误:
runfile('C:/Users/Usuario/Desktop/TFM/Task 1/TAS 3.py', wdir='C:/Users/Usuario/Desktop/TFM/Task 1')
Traceback (most recent call last):
File "<ipython-input-1-fc41d9ffae87>", line 1, in <module>
runfile('C:/Users/Usuario/Desktop/TFM/Task 1/TAS 3.py', wdir='C:/Users/Usuario/Desktop/TFM/Task 1')
File "C:\Users\Usuario\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\Users\Usuario\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Usuario/Desktop/TFM/Task 1/TAS 3.py", line 70, in <module>
table['Fcoef']=f_coef(table['Mfx'],table['X'],table['Press'])
File "C:/Users/Usuario/Desktop/TFM/Task 1/TAS 3.py", line 43, in f_coef
water=IAPWS95(P=Press, x=0) # To get density of the liquid
File "C:\Users\Usuario\Anaconda3\lib\site-packages\iapws\iapws95.py", line 396, in __init__
self.__call__(**kwargs)
File "C:\Users\Usuario\Anaconda3\lib\site-packages\iapws\iapws95.py", line 412, in __call__
if self.calculable:
File "C:\Users\Usuario\Anaconda3\lib\site-packages\iapws\iapws95.py", line 447, in calculable
elif self.kwargs["P"] and self.kwargs["rho"]:
File "C:\Users\Usuario\Anaconda3\lib\site-packages\pandas\core\generic.py", line 1478, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我的代码:
import pandas as pd
import matplotlib.pyplot as plt
import math
import numpy as np
import scipy.stats as stats
from iapws import IAPWS95
table = pd.read_csv('table_tidy.csv', sep = ',', header = 0)
D=8*10**-3
table=table.loc[table.X <= 0.15 ,:]
table=table.loc[table.Press > 6.89475728,:]
table=table.loc[table.Press < 15.857941744,:]
table=table.loc[table.Mfx<6781.1545,:]
table=table.loc[table.Mfx>1356.2309,:]
table=table.loc[table.flag == 'white',:]
def f_coef(Mflux,X,Press):
water=0
r=0
water=IAPWS95(P=Press, x=0) # To get density of the liquid
Fcoef=0
r=water.rho
Fcoef=((Mflux*(1-X))**2)/r
return Fcoef
def v_coef(Mflux,X,Press):
water=0
r=0
water=IAPWS95(P=Press, x=1) # To get density of the vapor
Vcoef=0
r=water.rho
Vcoef=((Mflux*(X))**2)/r
return Vcoef
def coefs(data):
data['Fcoef']=f_coef(data['Mfx'],data['X'],data['Press'])
data['Vcoef']=v_coef(data['Mfx'],data['X'],data['Press'])
return data
table = coefs(table) #first way
table['Fcoef']=f_coef(table['Mfx'],table['X'],table['Press']) #second way