本帖最后由 shiyanwei 于 2022-9-2 17:12 编辑
报这个错误i:TypeError: 'float' object is not iterable
请大神给指导一下,不太理解为什么会报这个错。
from pyecharts.charts import Bar
with open(r'D:\Downloads\sxgangwei.txt','r',encoding='utf-8') as qq:
neirong = qq.readlines()
# a = print(neirong)
dictCity = {}
for i in neirong:
if i == '薪资面议' :
continue
# print(i)
city = i.split(",")[2]
salary = i.split(",")[3]
daily = salary.split("/")[0]
# print(city,daily)
avg1 = daily.split("-")[0]
avg2 = daily.split("-")[1]
avg = (int(avg1)+int(avg2))/2
# print(avg)
if city not in dictCity.keys():
dictCity[city] = []
dictCity[city].append(avg)
print(dictCity)
for key,value in dictCity.items():
print(key)
print(value)
avg_value = sum(value)//len(value)
dictCity[key]= avg_value
print(dictCity)
bar = Bar()
bar.add_xaxis(list(dictCity.keys()))
bar.add_yaxis("各城市薪资",list(dictCity.values()))
bar.render("salary.html")
|