python数据分析实战项目—运用matplotlib可视化分析10000条北京各大区二手房区域信息(附源码)

开发工具

python版本:Python 3.6.1

python开发工具:JetBrains PyCharm 2018.3.6 x64

第三方库:pandas ;matplotlib ;seaborn

数据内容

在这里插入图片描述

实现代码

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')

sns.set_style({'font.sans-serif': ['simhei', 'Arial']})

lianjia_df = pd.read_csv('lianjia.csv')

# 添加房屋均价: 总价/房屋大小
df = lianjia_df.copy()
df['PerPrice'] = round(lianjia_df['Price'] / lianjia_df['Size'], 2)

# 重新摆放列位置
columns = ['Region', 'District', 'Garden', 'Layout', 'Floor', 'Year', 'Size', 'Elevator', 'Direction', 'Renovation',
           'PerPrice', 'Price']
df = pd.DataFrame(df, columns=columns)

# 二手房区域分组对比二手房数量和每平米价格
df_house_count = df.groupby('Region')['Price'].count().sort_values(ascending=False).to_frame().reset_index()
df_house_mean = df.groupby('Region')['PerPrice'].mean().sort_values(ascending=False).to_frame().reset_index()

f, [ax1, ax2, ax3] = plt.subplots(3, 1, figsize=(20, 20))

# 每平米单价对比图
sns.barplot(x='Region', y='PerPrice', palette='Blues_d', data=df_house_mean, ax=ax1)
ax1.set_title('北京各大区二手房每平米单价对比', fontsize=15)
ax1.set_xlabel('区域')
ax1.set_ylabel('每平米单价')

# 各区域二手房数量
sns.barplot(x='Region', y='Price', palette='Greens_d', data=df_house_count, ax=ax2)
ax2.set_title('北京各大区二手房数量对比', fontsize=15)
ax2.set_xlabel('区域')
ax2.set_ylabel('数量')

# 各区域二手房房屋总价
sns.boxplot(x='Region', y='Price', data=df, ax=ax3)
ax3.set_title('北京各大区二手房房屋总价', fontsize=15)
ax3.set_xlabel('区域')
ax3.set_ylabel('房屋总价')

plt.show()

运行效果

从第一个区域与每平米单价图中可以看到,西城、东城和海淀地区价格相对较高

从第二个区域与数量图中可以看到,海淀,朝阳,丰台和昌平数量都在2500以上

从第三个区域与总价图中可以看到,总价的平均价格都在1000以下

在这里插入图片描述

10000条二手房信息下载地址

https://url71.ctfile.com/f/13238771-530323628-1950bb
(访问密码:8835)

总结

这里主要运用了python的barplot绘制条形图函数和boxplot箱线图函数分析区域与每平米价格、数量和房屋总价的关系

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值