Search code examples
pythonpandasreplacegroup-by

How to replace one column values with another column values


Actually I want to replace the prefix with the mean here. How can i acheive it. When replacing it it is replacing with NaN but not with the mean values.

This is my code:

My code


Solution

  • Since the second column is a multi-index column, you are basically trying to set a single column as a dataframe. You will have to refer to the exact column name to do that replacement.

    z['ID']=z['teacher_number_of_previously_posted_projects']['mean']