pivot
然后重命名列:
out = df.pivot(index="id", columns="entity").reset_index()
out.columns = [f"{col[1]}_{col[0]}".replace("_value", "") for col in out.columns]
_id address_true email_true student_true address_extracted ... email_rater student_rater address_ratio email_ratio student_ratio
0 1 303 lake way [email protected] no 303 lake way ... False False 100 0 100
1 2 15 putin ave [email protected] yes 15 putnam ave ... True True 0 95 100
[2 rows x 13 columns]