呼唤远方
使用DataFrame.diff并在必要时将第一列转换为索引DataFrame.set_index:df = pd.DataFrame({ 'W':list('abc'), 'X':[10,5,4], 'Y':[7,8,9], 'Z':[1,1,0], 'E':[5,3,6],})df = df.set_index('W').diff(-1, axis=1)print (df) X Y Z EW a 3.0 6.0 -4.0 NaNb -3.0 7.0 -2.0 NaNc -5.0 9.0 -6.0 NaN