Deleting lines with repeated Labels on a Dataframe

Asked

Viewed 50 times

1

I need to delete in a dataframe lines that contain repeated labals, as highlighted in spine "B":

inserir a descrição da imagem aqui

Below is the result of how I would like it to stay after exclusion:

inserir a descrição da imagem aqui

  • Welcome(a) to the platform. And, from now on, I dirty the reading of the following articles: How to ask a good question? and Manual on how NOT to ask questions. Both articles will teach you how to elaborate a good question, avoiding negative and even closing votes. Good luck! Take full advantage of our potential and always come back!

2 answers

2


Hello, you can wear df.drop_duplicates() to filter the fields. Pandas import is implicit and dataframe creation I will also use your example that is so:


df_sem_duplicacao = df.drop_duplicates(subset=['B'])
df_sem_duplicacao

The parameter subset receives a list with column labels. By default, df.drop_duplicates(), removing only those that are exactly equal. But that’s not what we want, so I use the parameter subset to specify where I want to apply the filter.

2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.