首页 > 代码库 > 拉格朗日插值法

拉格朗日插值法

# -*- coding: utf-8 -*-import pandas as pdfrom scipy.interpolate import lagrangeinputfile=F:\\python数据挖掘\\chapter6\\chapter6\\demo\\data\\missing_data.xlsoutputfile=F:\\python数据挖掘\\chapter6\\chapter6\\demo\\tmp\\missing_data_sale.xlsdata=pd.read_excel(inputfile,header=None)#data[u‘销量‘][(data[u‘销量‘]<400)|(data[u‘销量‘]>5000)]=Nonedef ployinterp(s,n,k=5):    y=s[list(range(n-k,n))+list(range(n+1,n+1+k))]    print(y)    y=y[y.notnull()]    return lagrange(y.index,list(y))(n)for i in data.columns:    for j in range(len(data)):        if(data[i].isnull())[j]:            data[i][j]=ployinterp(data[i],j)            print(data[i][j])data.to_excel(outputfile,header=None,index=False)

 

拉格朗日插值法