## 相邻两个数据求比值 def neigh_rate(data): neigh_rate = {} # neigh_rate = [] # 报错 list assignment index out of range for i in range(len(data)): for j in range(i+1, len(data)): neigh_rate[i] = data[j] / data[i] result = list(neigh_rate.values()) # 提取字典值并转化成list格式 re_round = [round(x, 4) for x in result] # 将转化率保留四位小数 return re_round