gpt4 book ai didi

Creating a Column in dataframe by computing value with a condition dependent on two other columns, including complex math equation(通过使用依赖于其他两个列的条件计算值来在数据帧中创建列,包括复杂的数学公式)

转载 作者:bug小助手 更新时间:2023-10-25 13:06:18 31 4
gpt4 key购买 nike



This is the complex equation that I want

这就是我想要的复杂方程式


HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH


If the RH is less than 13% and the T is between 80 and 112, then the following adjustment is subtracted from HI:
ADJUSTMENT = [(13-RH)/4]*SQRT{[17-ABS(T-95.)]/17}
where ABS and SQRT are the absolute value and square root functions, respectively.

On the other hand, if the RH is greater than 85% and the T is between 80 and 87, then the following adjustment is added to HI:
ADJUSTMENT = [(RH-85)/10] * [(87-T)/5]

consider temp as a dataframe that has these columns 'RH', 'T' and we need to compute a column 'HI'.

将TEMP视为具有这些列‘RH’、‘T’的数据帧,我们需要计算列‘HI’。


I have implemented it this way using this (df.X * df.Y).where(df.Z == 'Value'):

我使用这个(df.X*df.Y)实现了它。其中(df.Z==‘Value’):


``py

temp['HI'] = -42.379 + 2.04901523*temp['T'] + 10.14333127*temp['RH'] - .22475541*temp['T']*temp['RH'] - .00683783**temp['T'] - 0.05481717**temp['RH'] + 0.00122874*temp['T']**2*temp['RH'] + .00085282*temp['T']*temp['RH']**2 - .00000199*temp['T']**2*temp['RH']*temp['RH']

#Rothfusz
temp['HI'] =(temp.HI- ((13-temp.RH)/4)*math.sqrt(17-abs(temp.T-95)/17)).where(temp.RH < 0.13 and (temp.T>80 and temp.T<112))
temp.['HI'] = (temp.HI+ (temp.RH-85) *0.1 *((87-temp.T)/5)).where(temp.RH > 0.85 and (temp.T>80 and temp.T<87))
#Steadman's
temp['HI'] = (0.5 * (temp.T + 61.0 + ((temp.T-68.0)*1.2) + (temp.RH*0.094))).where(temp.HI<80)
``

I am getting various errors with some tweaks. One of them are type error, one was "series integer/float mismatch", and one is this "must be real number, not DataFrame". Once I add datetime as one column to add timestamp to the dataframe for samples, this same code gives error: "Addition/subtraction of integers and integer-arrays with Timestamp is no longer supported. Instead of adding/subtracting n, use n * obj.freq"

我得到了一些调整的各种错误。其中一个是类型错误,一个是“序列整数/浮点数不匹配”,一个是“必须是实数,而不是DataFrame”。一旦我将datetime作为一列添加到示例的嵌套框架中,这段代码就会给出错误:“不再支持带Timestamp的整数和整数数组的加减运算。使用n * obj.freq代替加/减n”


更多回答
优秀答案推荐
更多回答

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com