Home > Enterprise >  Remove Values in Column Without Removing Anything Else
Remove Values in Column Without Removing Anything Else

Time:03-09

I have a data frame that looks like this: dataframe However, in col4, I have some repeating values that I want to delete but keep the first repeating value so that my data frame looks like this:modified dataframe

CodePudding user response:

You can only replace them to empty string:

df['col4'] = df['col4'].mask(df['col4'].duplicated(), '')

#thank you Corralien for alternative
df.loc[df['col4'].duplicated(), 'col4'] = ''

Or to missing values:

df['col4'] = df['col4'].mask(df['col4'].duplicated())
  • Related