pandas groupby apply a function. There are any references about pandas groupby apply a function in here. you can look below.