Filtering and filling Nan with mode in Pandas
df.loc[df["columnname"]==0,"columnname"]=np.nan
df["columnname"]=df.groupby("groupbycolumnname").columnname.transform(lambda x: x.fillna(x.mode()))
I have many qualitative variables in one column1 and corresponding qualitative values in another column which have blank values. I want to replace the blanks with the MODE value of each qualitative variable in column 1. For example if I have varibles such as Accountant, Engineer, Manager, etc. in column 1 and if I have Bachelor's degree as MODE for accountant, Master's for Engineer in column 2, I want to replace the coressponding blanks with Bachelor's and Master's Correctly. How can I achieve this in pandas?