python拉格朗日插值

來源:互聯網
上載者:User

標籤:list   range   index   inter   pytho   otn   input   port   tput   

#拉格朗日插值代碼import pandas as pd #匯入資料分析庫Pandasfrom scipy.interpolate import lagrange #匯入拉格朗日插值函數inputfile = ‘../data/catering_sale.xls‘ #銷量資料路徑outputfile = ‘../tmp/sales.xls‘ #輸出資料路徑data = pd.read_excel(inputfile) #讀入資料data[u‘銷量‘][(data[u‘銷量‘] < 400)][(data[u‘銷量‘] > 5000)]= None #過濾異常值,將其變為空白值#print(data)#自訂欄向量插值函數#s為列向量,n為被插值的位置,k為取前後的資料個數,預設為5def ployinterp_column(s, n, k=5):  s1=s.copy()  y = s1[list(range(n-k, n))+list(range(n+1, n+1+k))]#取數  y = y[y.notnull()] #剔除空值  return lagrange(y.index, list(y))(n) #插值並返回插值結果#逐個元素判斷是否需要插值 data[i].isnull()返回布爾數組# 0      False# 1      False# 2      False# 3      False# 4      Falsefor i in data.columns:  for j in range(len(data)):    if (data[i].isnull())[j]: #如果為空白即插值。        data[i][j] = ployinterp_column(data[i], j)        print(data[i][j])data.to_excel(outputfile) #輸出結果,寫入檔案

 

python拉格朗日插值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.