在python中获取减法错误?

在python中获取减法错误?,python,pandas,Python,Pandas,代码中出现的问题是,它没有在cds2d中写入值,而是将cds2d写入cds2d列下的所有位置。请通读,以便获得更好的帮助。例如,解释您试图做什么,提供一些示例输入和预期输出。 import pandas as pd df=pd.read_excel("E:\Hatch\Consultancy Hatch\FUGRO\Project\Panam_DTM_26042021\Profiles\ProfilesPyt.xlsx"); for i in range(155):

代码中出现的问题是,它没有在cds2d中写入值,而是将cds2d写入cds2d列下的所有位置。

请通读,以便获得更好的帮助。例如,解释您试图做什么,提供一些示例输入和预期输出。
import pandas as pd

df=pd.read_excel("E:\Hatch\Consultancy Hatch\FUGRO\Project\Panam_DTM_26042021\Profiles\ProfilesPyt.xlsx");

for i in range(155):
    df_new=df[df['prof_label']==i+1];
    a=df_new[['Panam_DTM_']].idxmin();
    b=df_new[['cds2d']].loc[a];
    df_new.loc[:, "cds2d"] = df_new["cds2d"].apply(lambda x: x - b);
    df[df['prof_label']==i+1]=df_new;
    
df.to_csv(r"E:\Hatch\Consultancy Hatch\FUGRO\Project\Panam_DTM_26042021\Profiles\ProfilesPyt.csv