基于组的插值

2024-04-24 15:58:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试基于test数据帧上的输入数据(test数据输入)执行插值。我现在设置它的方式是按危险进行设置,因此我首先创建了一个仅包含火灾危险的数据帧(见下文),然后对特定的危险组执行插值:

目标是在测试数据输入中有一列同时包含危险类型和因素。我遇到的一个问题是,test数据输入中的保险金额与test数据帧中的保险金额完全匹配。它仍然插值,无论它是否是一个完美的匹配

fire_peril_test=test_data[test_data['Peril Type'=='Fire']]
from scipy import interpolate
x=fire_peril_test['Amount of Insurance']
x=fire_peril_test['Amount Of Insurance']
y=_fire_peril_test['Factor']
y=fire_peril_test['Factor']
f=interpolate.interp1d(x,y)
xnew=test_data_Inputs["Amount of Insurance"]
ynew=f(xnew)


test_data_Inputs=pd.DataFrame({'Amount of Insurance':[320000,330000,340000]})
test_data=pd.DataFrame({'Amount of Insurance':[300000,350000,400000,300000,350000,400000],'Peril Type':['Fire','Fire','Fire','Water','Water','Water'],'Factor':[.10,.20,.35,.20,.30,.40]})

感谢所有的帮助


Tags: of数据testdatatypeamountfire插值
1条回答
网友
1楼 · 发布于 2024-04-24 15:58:16
amount_of_insurance=pd.DataFrame()
df['Amount of Insurance']=pd.melt(df['Amount of Insurance'],id_vars=['Amount Of Insurance'],var_name='Peril Type',value_name='Factor')

for peril in df['Amount of Insurance']['Peril Type'].unique():
    #peril='Fire'
    x=df['Amount of Insurance']['Amount Of Insurance'][df['Amount of Insurance']['Peril Type']==str(peril)]
    y=df['Amount of Insurance']['Factor'][df['Amount of Insurance']['Peril Type']==str(peril)]
    f=interpolate.interp1d(x,y)
    xnew=data_for_rater[['Enter Amount of Insurance']]
    ynew=f(xnew)
    append_frame=data_for_rater[['Group','Enter Amount of Insurance']]
    append_frame['Peril Type']=str(peril)
    append_frame['Factor']=ynew
    amount_of_insurance=amount_of_insurance.append(append_frame)

我的解决方案与我的实际数据。我基本上把这些数据融为一体,以便能够循环遍历独特的危险类型。如果你们有别的选择请告诉我

相关问题 更多 >