How delete irrelevant rows from dataframe?

by asymon   Last Updated October 20, 2019 05:26 AM

Imagine that in column S1 an event, and in column RES its result. How can I leave in the data frame only the last result of each event?

Source data frame:

S1      RES DATE
red     1   01.01.2019
red     2   02.01.2019
red     1   03.01.2019
red     22  04.01.2019
green   1   05.01.2019
green   4   06.01.2019
black   1   07.01.2019
black   0   08.01.2019
black   1   09.01.2019

Required data frame:

S1      RES DATE
red     22  04.01.2019
green   4   06.01.2019
black   1   09.01.2019


Answers 1


df.drop_duplicates(subset=['S1'], keep='last')

asymon
asymon
October 20, 2019 05:21 AM

Related Questions


Updated July 30, 2018 21:26 PM

Updated March 12, 2017 23:26 PM

Updated July 25, 2017 22:26 PM

Updated December 31, 2017 16:26 PM