取出列2每组对应的最小值
data = pd.DataFrame({
'aa':['a','b','c','b','c']
,'b':['a','b','c','b','c']
,'c':['a','b','c','b','c']
,'d':['a','b','c','b','c']
,'e':['2021-10-01','2021-10-06','2021-10-08','2021-10-07','2021-10-07']
})
data['e']=pd.to_datetime(data['e']) # 将注册日期转换为日期格式
data1 = data.groupby("aa").agg({'e':[np.min]})
ad_min = data.groupby('aa').apply(lambda t: t[t.e==t.e.min()])
ad_min.reset_index(drop=True, inplace=True)

取出列2的最大值与最小值
import numpy as np
df = pd.DataFrame({'item':['A','A','A','B','B','B']
,'year':[2010,2011,2012,2016,2019,2018]
,'value':[20,25,32,20,40,50]})
df.groupby("item").agg({'year':[np.min, np.max]})
以列2排序后再找出列3极值的差值
import numpy as np
df = pd.DataFrame({'item':['A','A','A','B','B','B']
,'year':[2010,2011,2012,2016,2019,2018]
,'value':[20,25,32,20,40,50]})
g = df.sort_values('year').groupby('item')
out = g['value'].last() - g['value'].first()
out
