. 1 from scipy.interpolate Import Lagrange 2 Import PANDAS AS PD . 3 Import numpy AS NP . 4 . 5 # loading data . 6 Data = pd.read_excel ( " ./qs.xlsx " ) . 7 # Print ( "Data: \ n-", Data) . 8 Print ( " column index data is: \ n " , data.columns) . 9 10 # set missing values before and after the n to construct Lagrange relationship . 11 n. 5 = 12 is 13 is # cycle through the position of missing values 14 for i inRange (data.shape [0]): 15 Print (I) 16 # determines if a value is missing, interpolation proceeds . 17 IF np.isnan (data.iloc [I,. 1 ]): 18 is Print ( " % d of behavior missing values " % I) . 19 iF in < 0: 20 is Start = 0 21 is the else : 22 is Start in = 23 is # acquired before and after the missing values of n data - whether that there is a missing data before and after the value n 24 mask = data .iloc [Start: n-I + +. 1,. 1 ] 25 # Get index 26 is X =mask.index 27 Print ( " X: \ n- " , X) 28 # index of the row containing the missing values removed 29 X = X [mask.notnull ()] 30 Print ( " X: \ n- " , X) 31 is # or without missing values, wherein the removed portion containing missing values 32 Y = mask [mask.notnull ()] values. # containing missing values array 33 is Print ( " Y: \ n- " , Y) 34 is # Construction pull Grange polynomial, Lagrange polynomial returns the object 35 La = Lagrange (X = X, W = Y) 36 # Lagrangian interpolating polynomial 37 [ data.iloc [I,. 1] = La ([I]) 38 is Print ( " result after interpolation complete: \ n- " , Data)
[Data Analysis & Data Mining] Lagrange polynomial
Guess you like
Origin www.cnblogs.com/Tree0108/p/12116101.html
Ranking