主页 M

python应用matplotlib可视化链家二手房

2020-04-08 网页编程网 网页编程网
# -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt 
 
# 导入数据,并进行初步观察
lianjia_df = pd.read_csv('lianjia.csv')
#删除id
lianjia_df.drop('Id',axis=1,inplace=True)
#print(lianjia_df.head(10))
#增加新的列
lianjia_df['UnitPrice']=round(lianjia_df['Price']/lianjia_df.Size,2)
mean_price=lianjia_df.groupby('Region',sort=False)['UnitPrice'].mean()#每个城区单价
print(mean_price)
plt.rcParams['font.sans-serif']=['SimHei']
y=mean_price
x=lianjia_df.Region.unique()
plt.figure(figsize=(25,12))
plt.bar(x,y)
阅读原文
阅读 4009
123 显示电脑版