python读取excel指定列名,dataframe连接,两列相减作为第三列的值
作者:互联网
# encoding: utf-8 import arcpy import xlrd import pandas as pd path=r"D:\pyWork\resultAna\dl" day=29 while(day>28): pp=path+"\\ppday"+str(day)+".xls" cs = path + "\\csday" + str(day) + ".xls" #读取excel指定列名 datapp=pd.read_excel(pp,names=['id','score']) datacs=pd.read_excel(cs,names=['id','score']) #基于某列来连接两个dataframe jg=pd.merge(datapp,datacs,how = 'left',on='id') #添加一列 jg['per']=(jg['score_y'])/jg['score_x'] jg.to_excel("./all/day" + str(day) + ".xls") #jg['per']=jg.apply(lambda k: function((k.score_y-k.score_x)/k.score_x), axis = 1) day=day-1
标签:第三列,python,excel,id,score,pd,jg,day 来源: https://blog.csdn.net/A873054267/article/details/88094713