import numpy as np import pandas as pd import matplotlib.pyplot as mp df=pd.read_excel('C:/Users/86147/OneDrive/文档/66666.xlsx',header=0,usecols=(1,)) mylist1=df.values.tolist() room=[] for i in mylist1: room.append(i[0]) df=pd.read_excel('C:/Users/86147/OneDrive/文档/66666.xlsx',header=0,usecols=(2,)) mylist1=df.values.tolist() tomp=[] for i in mylist1: tomp.append(i[0]) room_tomp=zip(room,tomp) avge=[] ls=[] for i in range(1,185): ls.clear() for k,v in room_tomp: if k==i: ls.append(v) s=sum(ls) avg=s/2928 avge.append(avg) print(avge)修改这个代码让avge输出都为正常值
时间: 2024-02-15 15:05:56 浏览: 95
Matplotlib.pyplot 三维绘图的实现示例
可以在每次遍历时重新生成room_tomp,避免其被清空的问题。修改后的代码如下:
```
import numpy as np
import pandas as pd
import matplotlib.pyplot as mp
df=pd.read_excel('C:/Users/86147/OneDrive/文档/66666.xlsx',header=0,usecols=(1,))
mylist1=df.values.tolist()
room=[]
for i in mylist1:
room.append(i[0])
df=pd.read_excel('C:/Users/86147/OneDrive/文档/66666.xlsx',header=0,usecols=(2,))
mylist1=df.values.tolist()
tomp=[]
for i in mylist1:
tomp.append(i[0])
avge=[]
for i in range(1,185):
ls=[]
room_tomp=zip(room,tomp)
for k,v in room_tomp:
if k==i:
ls.append(v)
s=sum(ls)
avg=s/2928
avge.append(avg)
print(avge)
```
这样就可以得到每个房间的平均温度了。
阅读全文