update column value of pandas groupby().last()
问题 Given dataframe: dfd = pd.DataFrame({'A': [1, 1, 2,2,3,3], 'B': [4, 5, 6,7,8,9], 'C':['a','b','c','c','d','e'] }) I can find the last C value of each A group by using dfd.groupby('A').last()['C'] However, I want to update the C values to np.nan. I don't know how to do that. Method such as: def replace(df): df['C']=np.nan return replace dfd.groupby('A').last().apply(lambda dfd: replace(dfd)) Does not work. I want the result like: dfd_result= pd.DataFrame({'A': [1, 1, 2,2,3,3], 'B': [4, 5, 6,7