1 #Lagrange Interpolation method2 ImportPandas as PD#Import Module3 fromScipy.interpolateImportLagrange4 5Inputfile = R'M:\pycache\pythonData\pythondata\chapter4\chapter4\demo\data\catering_sale.xls'6OutputFile =r'M:\pycache\pythonData\pythondata\chapter4\chapter4\demo\tmp\sales.xls' #input/Output data7 8data =Pd.read_excel (inputfile)9Data[u'Sales'[(Data[u'Sales']<400) | (Data[u'Sales']>5000)] = None#filter values and turn them into null valuesTen One #defining column vector interpolation functions A #s is the column vector, N is the interpolated position, K is the number of data before and after the fetch, the default is 5 - - defPloyintterp_column (s,n,k=5): they = s[list (range (n-k,n)) +list (range (n+1,n+1+k)] -y = Y[y.notnull ()]#reject null value - returnLagrange (Y.index,list (y)) (n)#interpolate and return interpolation results - #determine if interpolation is required on an element-by-component basis + forIinchData.columns: - forJinchRange (len (data)): + if(Data[i].isnull ()) [j]: ADATA[I][J] =Ployintterp_column (data[i],j) at -Data.to_excel (outputfile)
Lagrange Interpolation method