excel - How can I find minimum and maximum value of date for ID 1 and 5 using python pandas? -
here, shown in image want find minimum , maximum value of date id 1 , 5. id 1 minimum date 2016-01-27 17:13:19 , maximum 2016-03-28 00:56:43. same id 5.
you can use aggregate,
consider df
date id 0 2016-3-28 00:56:43 1 1 2017-3-28 00:56:43 1 2 2005-3-28 00:56:43 1 3 2010-3-28 00:56:43 1 4 2002-3-28 00:56:43 1 5 2017-3-29 00:56:43 1 6 2004-3-28 00:56:43 5 7 2002-3-21 00:56:43 5 8 2015-3-28 00:56:43 5 9 2017-4-28 00:56:43 5 10 2009-3-28 00:56:43 5 11 2007-3-28 00:56:43 5
you can min , max date each id using
df.groupby('id').date.agg(['min', 'max']).reset_index()
you get
id min max 0 1 2002-3-28 00:56:43 2017-3-29 00:56:43 1 5 2002-3-21 00:56:43 2017-4-28 00:56:43
wiki
Comments
Post a Comment