'Remove a value from a cell based on another value of the same row in python

i have a data set presented as follow: FORMAT TO CONVERT

I would like to classify values in part name and material column based on their value in ID but I am confused about the code to use in python. I know it is a conditional code but I don't know which one to use exactly. The final result should look like this final result



Solution 1:[1]

You want this ?

df['Part name']=np.where(df['ID']=='P',df['Part name'],np.nan)
df['Material']=np.where(df['ID']=='M',df['Material'],np.nan)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DataSciRookie