def cal(grp):
row = grp.head(1)
row['AETERM'] = grp['AETERM'].tolist()
return row
temp1_a = temp1_a.groupby('Subject',as_index=False).apply(cal)
ValueError: Length of values does not match length of index
报错原因是两个长度不匹配,把这一行删除试试呢:
row = grp.head(1)