Skip to content
Advertisement

Python : Dropping specific rows in a dataframe and keep a specif one

Let’s say that I have this dataframe

JavaScript

I want to reduce this dataframe ! I want to reduce only the rows that contains the string “info” by keeping the ones that have the highest level in the column “Group”. So in this dataframe, it would mean that I keep the row “ID_info_1” in the group 4, and “ID_info_1” in the group 3. In addition, I want to change the their value in the column “Group” to 1.

So at the end I would like to get this new dataframe where the indexing is reset too

JavaScript

Anyone has an efficient idea ?

Thank you

Advertisement

Answer

How about this:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement