#!/usr/bin/env python
# coding: utf-8
# In[110]:
import pandas as pd
def fun(ndf):
ids = ndf['jid'].to_list()
d = ndf['d'].to_list()
mdd = []
aa, bb = [], []
for i,idsi in enumerate(ids):
if i != 0 and idsi != ids[i-1]:
if len(aa) == 1: mddi = 0
else: mddi = round(sum(bb)/(len(aa)-1),2)
mdd += [mddi]*len(aa)
aa, bb = [idsi], [float(d[i])]
elif i == 0 or idsi == ids[i-1]:
aa.append(idsi)