pandas问题:如何求出每周close的最大值

截取了一部分股票相关的数据,我想把每一周收盘价close最大的那天找出来,该怎么操作,求指导~

img

取出date,计算是第几周week_num,然后用week_num+code组成key
遍历每一行数据,写入字典max_dict
如果close值大的话,则更新字典的值

df =pd.read_excel("data.xlsx")
nrows = df.shape[0]
ncols = df.columns.size
max_dict = {}
for i in range(1, nrows):
    data = df.iloc[i]
    week_num = data[0].isocalendar()[1]
    key = data[1] + "-" + str(week_num)
    if max_dict.get(key) is not None:
        close_now = max_dict.get(key)[2]
        close_tmp = data[2]
        if close_now < close_tmp:
            max_dict[key] = data
    else:
        max_dict[key] = data
print(max_dict)