1 import pandas 2 excel=pandas.read_excel('填充資料.xlsx',header=3,index_col='id') 3 excel['mutiply']=excel['store']*0.5 4 for i in excel.index: 5 excel['data1'].at[i]=excel['data'].at[i]*excel['store'].at[i] #data1這個列名必須在excel里面存在,否則程式會報錯 6 7 8 excel['store']=excel['store']+2 #對著一列的每個元素加2 9 10 def add_2(x): 11 return x+2 12 13 excel['data']=excel['data'].apply(add_2) #對data這列的每個元素加2,也可以用lambda x:x+2代替 14 print(excel)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/138077.html
標籤:Python
上一篇:淺談Python內置物件型別——數字篇(附py2和py3的區別之一)
下一篇:對excel進行排序及多重排序
