大佬们,为什么我的数据可视化图形出不来?

常见问题与解答 2021-03-01 10:14:13 15

摘要

fromflaskimportFlask,render_template app=Flask(__name__) fb=open(r'过滤后的mysql.csv',encoding='utf-8')data=fb.readlines()line=data[0].split(',')#print(line)print(line[3],line[4],line[13],line[17],"出租率")cityM……

from flask import Flask,render_template



 



app = Flask(__name__)



 



fb = open(r'过滤后的mysql.csv', encoding='utf-8')



data = fb.readlines()



line = data[0].split(',')



# print(line)



print(line[3], line[4], line[13], line[17], "出租率")



cityMap = {}



for i in data[1:]:



    sum1 = i.split(",")



    province = sum1[3]



    city = sum1[4]



    sum2 = sum1[13]



    shouchu = sum1[17]



    bilv = int(shouchu) / int(sum2)



    if province+city in cityMap:



        cityList = cityMap[province+city]



        cityList[0] = cityList[0] + 1



        cityList[1] = cityList[1] + bilv



        cityMap[province+city] = cityList



    else:



        cityMap[province+city] = [1, bilv]



 



# print(cityMap)



# print(type(cityMap))



ccc = {}



for i in cityMap:



    sum = cityMap[i][1] / cityMap[i][0]



    ccc[i] = round(sum,2)



# print(ccc)



list1 = list(ccc.items())



# print(list1)



bbb = dict(sorted(list1,key=lambda x:x[1],reverse=True)) # 降序排序



list2 = list(bbb.items())[:10] # 取前10



#    bbb



aaa = dict(list2)



# print(aaa)



@app.route('/')



def hello_world():



    return render_template("hello.html",cityMap = aaa)



 



if __name__ == '__main__':



    app.run()


评论(0)
1422369665