I understand that the root of the problem is that I loop through the columns of data in the code, but when I add data, the columns of data change, and when I reorder the index, the problem occurs. However, when we use a variable temp to deep copy data in advance and use the temp column as the loop condition, the problem is solved directly.
def FE3(data):
temp=data.copy() #change
for col in temp.columns: #change
mean_map=org_.groupby(col)["accident_risk"].mean()
data[f"org_{col}"]=data[col].map(mean_map)
if col == "curvature":
data=data.sort_values(by="org_curvature")
data["org_curvature"]=data["org_curvature"].fillna(method="ffill")
data=data.sort_index()
return data