Suppose I have the following Dataframe
final raw act wc Start Finish
abc xyz 30 M5 17-01-2022 06:00 14-07-2031 02:36
abc xyz 40 F4 17-01-2022 06:00 14-07-2031 02:36
abc xyz 50 F6 17-01-2022 06:00 14-07-2031 02:36
abc xyz 60 F8 17-01-2022 06:00 14-07-2031 02:36
abc pqr 40 M14S 17-01-2022 06:00 18-01-2026 17:21
abc pqr 50 M12 17-01-2022 06:00 18-01-2026 17:21
abc pqr 60 M14S 17-01-2022 06:00 18-01-2026 17:21
abc pqr 20 F3 17-01-2022 06:00 14-07-2031 02:36
abc pqr 40 F4 17-01-2022 06:00 14-07-2031 02:36
abc pqr 50 F6 17-01-2022 06:00 14-07-2031 02:36
I would like to take the two rows from here, one is
abc xyz 50 F6 17-01-2022 06:00 14-07-2031 02:36
another one is
abc pqr 50 F6 17-01-2022 06:00 14-07-2031 02:36
The logic would be that for each raw, pick up the next row where wc is either F3, F4 and the act is maximum. Here for xyz, F4 is there, so the next row also for pqr, both F3, F4 are there but maximum act is 40.
I did it using pd.shift()
dft = dfUno.loc[dfUno['wc'].shift().eq('F4')]
But I would like to see it in a more generic way, may be extracting using iterrows(). Like, my code is only true for F4. I want to extract the dataframe used for above F4/ F3 also.
Expected outcome for this:
final raw act wc Start Finish
abc xyz 30 M5 17-01-2022 06:00 14-07-2031 02:36
abc xyz 40 F4 17-01-2022 06:00 14-07-2031 02:36
abc pqr 40 M14S 17-01-2022 06:00 18-01-2026 17:21
abc pqr 50 M12 17-01-2022 06:00 18-01-2026 17:21
abc pqr 60 M14S 17-01-2022 06:00 18-01-2026 17:21
abc pqr 20 F3 17-01-2022 06:00 14-07-2031 02:36
abc pqr 40 F4 17-01-2022 06:00 14-07-2031 02:36
pls suggest something, how to do it.