(Jan-22-2022, 06:28 PM)bnadir55 Wrote: Thx,Yes,but what i mean that you should poste the a working Dataframe sample,the add image as additional info about wanted result.
here is what I need return the left table with all the rows and columns that carry the max(Order_date) grouped by order_ID (see results on the right table)
see in attachment :
Most of here work with Pandas sporadically or not all,then is difficult to answer if can not teste stuff out.
So i have to make the DataFrame to test stuff out.
import pandas as pd from io import StringIO data = StringIO('''\ order id,order date,order requester,order urgency 1,10/1/2022,James,A 1,10/2/2022,Don,A 1,10/3/2022,Mike,B 2,10/4/2022,Mike,B 2,10/5/2022,Don,B 2,10/6/2022,James,B 3,10/7/2022,James,A 3,10/8/2022,Don,A 3,10/9/2022,Don,C 4,10/10/2022,Mike,C''') df_1 = pd.read_csv(data, sep=',') df_1["order date"] = pd.to_datetime(df_1["order date"]) df_2 = df_1.groupby(['order id'],as_index=False)[['order date']].max()So now can merge DataFrames based on df_2 groupby result.
This match your wanted result in image.
>>> df_3 = df_1.merge(df_2, on=['order id', 'order date'], how='inner') >>> df_3 order id order date order requester order urgency 0 1 2022-10-03 Mike B 1 2 2022-10-06 James B 2 3 2022-10-09 Don C 3 4 2022-10-10 Mike C