# -*- coding: utf-8 -*-
#Author Mr.xu
import pandas
import numpy
import matplotlib.pyplot as plt
import csv
import matplotlib
from IPython import display
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
file = 'F:\\lianjia.csv'
x = ['陶然亭','东直门','木樨地','西北旺','朝阳公园','宣武门','世纪城']
y = []
d = {}
c = {}
with open(file,'r',encoding='utf-8',errors='ignore') as f:
content = csv.reader(f)
for con in content:
if len(con)==0:
pass
elif con[1] in x:
y.append([con[1],con[7]])
for i in y:
#
if i[0] in d:
d[i[0]] = d[i[0]] + float(i[1])
c[i[0]] = c[i[0]] + 1
else:
d.setdefault(i[0],float(i[1]))
c.setdefault(i[0],int(1))
y1 = [[x,d[x]] for x in d]
y2 = [[x,c[x]] for x in c]
avg = {}
for i in range(len(y2)):
if y1[i][0]==y2[i][0]:
avg[y1[i][0]] = round(y1[i][1]/y2[i][1],2)
plt.bar(avg.keys(),avg.values())
plt.xlabel('区域')
plt.ylabel('平均价格')
plt.title('北京部分地区租房平均价格')
plt.savefig('北京租房数据分析')
plt.show()
北京部分地区房租评价价格分析
最新推荐文章于 2023-04-21 10:59:37 发布