Home > Enterprise >  Remove a value from a cell based on another value of the same row in python
Remove a value from a cell based on another value of the same row in python

Time:05-05

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

CodePudding user response:

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)
  • Related