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

文章目录

*
开发工具
数据内容
实现代码
运行效果
10000条二手房信息下载地址
总结

开发工具

python版本:Python 3.6.1

python开发工具:JetBrains PyCharm 2018.3.6 x64

第三方库:pandas ;matplotlib ;seaborn

数据内容

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

; 实现代码

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以下

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

; 10000条二手房信息下载地址

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

总结

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

Original: https://blog.csdn.net/sha1_mi/article/details/122116203
Author: 程序猿沙弥
Title: python数据分析实战项目—运用matplotlib可视化分析10000条北京各大区二手房区域信息(附源码)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/699268/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球