79789241

Date: 2025-10-13 12:03:31
Score: 0.5
Natty:
Report link

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
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: osquer kkzlk