import platform
from spider_tao365_cleaner import Tao365Cleaner
import pandas as pd
import json
import numpy
class Tao365Analysis(Tao365Cleaner):
# 清洗数据后,执行数据分析
top_text = "使用 Python、Pandas、Flask框架、ECharts等技术实现"
def chart001(self):
# 柱状图 - 展示各行政区房屋均价
# 读取清洗后的数据文件
result_df = self.read_clean_result_file()
# 从字典对象导入数据
df = pd.DataFrame(result_df)
# 根据地址分组并计算每平米的平均价
mean_data = df.groupby(['地址'], as_index=False)['每平方价格'].agg({'每平方价格': 'mean'}).round()
# 取出地址列数据
address = mean_data['地址'].unique()
# 取出每平方价格列数据
price = mean_data['每平方价格'].unique()
# 定义表格顶部title
title = "各行政区房屋均价展示"
# 定义表格顶部说明
text = self.top_text
# 定义图表title
chart_title = '各行政区房屋均价展示'
# 定义图表横坐标
chart_x = '所在地区'
# 定义图表纵坐标
chart_y = '房屋均价'
# 定义图表单位
unit = '元'
# 定义图表类型
types = 'bar'
# 组装图表json数据
data_json = {
'data1': address.tolist(),
'data2': price.tolist(),
'title': title,
'text': text,
'chartTitle': chart_title,
'chartX': chart_x,
'chartY': chart_y,
'unit': unit,
'type': types
}
# 将json数据写入文件
with open('../data/chart001.json', 'w', encoding='utf-8') as write_f: # 打开本地文件
json.dump(data_json, write_f, indent=4, ensure_ascii=False) # python对象转换成json对象
def chart002(self):
# 柱状图 - 展示各行政区房屋数量
# 读取清洗后的数据文件
result_df = self.read_clean_result_file()
# 从字典对象导入数据
df = pd.DataFrame(result_df)
# 将数据根据地址分组
g = df.groupby('地址')
# 统计分组后的数量
df_region = g.count()['小区']
# 获取分组后的地址数据
address = df_region.index.tolist()
# 获取分组后的数量
count = df_region.values.tolist()
# 定义表格顶部title
title = "各行政区房屋数量"
# 定义表格顶部说明
text = self.top_text
# 定义图表title
chart_title = '各行政区房屋数量'
# 图表横坐标
chart_x = '所在地区'
# 图表纵坐标
chart_y = '房源数量/套'
# 图表单位
unit = '套'
# 图表类型
types = 'bar'
# 组装图表json数据
data_json = {
'data1': address,
'data2': count,
'title': title,
'text': text,
'chartTitle': chart_title,
'chartX': chart_x,
'chartY': chart_y,
'unit': unit,
'type': types
}
# 将json数据写入文件
with open('../data/chart002.json', 'w', encoding='utf-8') as write_f: # 打开本地文件
json.dump(data_json, write_f, indent=4, ensure_ascii=False) # python对象转换成json对象
def chart003(self):
# 折线图 - 展示南京市各区房屋均价
# 读取清洗后的数据文件
result_df = self.read_clean_result_file()
# 从字典对象导入数据
df = pd.DataFrame(result_df)
# 根据地址分钟并计算每平米的平均价
mean_data = df.groupby(['地址'], as_index=False)['每平方价格'].agg({'每平方价格': 'mean'}).round()
# 取出地址列数据
address = mean_data['地址'].unique()
# 取出每平方价格列数据
price = mean_data['每平方价格'].unique()
# 定义表格顶部title
title = "各行政区房屋均价"
# 定义表格顶部说明
text = self.top_text
# 图表title
chart_title = '各区房屋均价'
# 图表横坐标
chart_x = '所在地区'
# 图表纵坐标
chart_y = '房屋均价'
# 单位
unit = '元'
# 图表类型
types = 'line'
# 组装图表json数据
data_json = {
'data1': address.tolist(),
'data2': price.tolist(),
'title': title,
'text': text,
'chartTitle': chart_title,
'chartX': chart_x,
'chartY': chart_y,
'unit': unit,
'type': types
}
# 将json数据写入文件
with open('../data/chart003.json', 'w', encoding='utf-8') as write_f: # 打开本地文件
json.dump(data_json, write_f, indent=4, ensure_ascii=False) # python对象转换成json对象
def chart004(self):
# 柱状图 - 南京各区域二手房平均建筑面积
# 读取清洗后的数据文件
result_df = self.read_clean_result_file()
# 从字典对象导入数据
df = pd.DataFrame(result_df)
# 根据地址分组并计算平均建筑面积
mean_data = df.groupby(['地址'], as_index=False)['建筑面积'].agg({'建筑面积': 'mean'}).round()
# 获取地址列数据
address = mean_data['地址'].unique()
# 获取建筑面积列数据
area = mean_data['建筑面积'].unique()
arr = []
color_arr = ["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"
]
for k, i in enumerate(area):
arr.append({'value':i,'itemStyle':{'color':color_arr[k]}})
# 定义表格顶部title
title = "各行政区二手房平均建筑面积"
# 定义表格顶部说明
text = self.top_text
# 定义图表title
chart_title = '各区域二手房平均建筑面积'
# 定义横坐标
chart_x = ''
# 定义纵坐标
chart_y = '建筑面积(㎡)'
# 单位
unit = ''
# 图表类型
types = 'bar'
# 组装图表json数据
data_json = {
'data1': address.tolist(),
'data2': arr,
'title': title,
'text': text,
'chartTitle': chart_title,
'chartX': chart_x,
'chartY': chart_y,
'unit': unit,
'type': types
}
# 将json数据写入文件
with open('../data/chart004.json', 'w', encoding='utf-8') as write_f: # 打开本地文件
json.dump(data_json, write_f, indent=4, ensure_ascii=False) # python对象转换成json对象
def chart005(self):
# 柱状图 - 南京各区域二手房房源朝向
# 读取清洗后的数据文件
result_df = self.read_clean_result_file()
# 从字典对象导入数据
df = pd.DataFrame(result_df)
# 将数据根据房屋朝向分组
g = df.groupby('房屋朝向')
# 统计分组后的数量
df_region = g.count()['小区']
# 获取分组后的房屋朝向分组数据
address = df_region.index.tolist()
# 获取分组后的房屋朝向数量
count = df_region.values.tolist()
# 定义表格顶部title
title = "区域二手房房源朝向分布情况"
# 定义表格
没有合适的资源?快使用搜索试试~ 我知道了~
源码 - flask 和 echarts 使用柱状图折线图等可视化图表展示二手房统计数据
共211个文件
gif:75个
js:42个
css:21个
5星 · 超过95%的资源 需积分: 5 18 下载量 69 浏览量
2023-01-09
11:19:59
上传
评论
收藏 4.96MB ZIP 举报
温馨提示
一、实战场景 二、知识点 python 基础语法 python 文件读写 pandas 数据处理 flask web 框架 echarts 图表 jinja 模版 三、菜鸟实战 初始化 Flask 框架,设置路由 各行政区房屋均价柱状图分析 echarts 渲染柱状图 各面积区间房屋占比饼状图 echarts 渲染饼状图 运行结果 运行截图 数据示例
资源推荐
资源详情
资源评论
收起资源包目录
源码 - flask 和 echarts 使用柱状图折线图等可视化图表展示二手房统计数据 (211个子文件)
bootstrap.css 203KB
bootstrap.min.css 156KB
icofont.min.css 90KB
animate.css 80KB
layui.css 73KB
bootstrap-grid.css 70KB
boxicons.css 69KB
animate.min.css 57KB
boxicons.min.css 52KB
bootstrap-grid.min.css 50KB
style.css 26KB
aos.css 25KB
venobox.css 20KB
layer.css 14KB
layui.mobile.css 10KB
laydate.css 7KB
animations.css 7KB
bootstrap-reboot.css 5KB
bootstrap-reboot.min.css 4KB
code.css 1KB
transformations.css 683B
tao365_detail.csv 432KB
tao365_clean.csv 301KB
boxicons.eot 224KB
iconfont.eot 46KB
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
4.gif 6KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
41.gif 4KB
38.gif 4KB
65.gif 3KB
32.gif 3KB
45.gif 3KB
7.gif 3KB
12.gif 3KB
26.gif 3KB
60.gif 3KB
2.gif 3KB
40.gif 3KB
25.gif 3KB
19.gif 3KB
66.gif 3KB
18.gif 3KB
46.gif 3KB
10.gif 3KB
28.gif 3KB
51.gif 3KB
57.gif 3KB
67.gif 3KB
0.gif 3KB
48.gif 3KB
43.gif 3KB
30.gif 2KB
61.gif 2KB
33.gif 2KB
69.gif 2KB
14.gif 2KB
47.gif 2KB
36.gif 2KB
49.gif 2KB
58.gif 2KB
6.gif 2KB
54.gif 2KB
53.gif 2KB
56.gif 2KB
62.gif 2KB
31.gif 2KB
55.gif 2KB
35.gif 2KB
15.gif 2KB
loading-2.gif 2KB
37.gif 1KB
68.gif 1KB
52.gif 777B
loading-1.gif 701B
共 211 条
- 1
- 2
- 3
资源评论
- CyberNinja2023-07-26这个文件提供了清晰的教程,让我能够迅速上手并成功展示二手房统计数据。
- 贼仙呐2023-07-26作者用简洁的语言解释了如何使用柱状图和折线图等图表展示数据,非常实用。
- 杜拉拉到杜拉拉2023-07-26我以前对flask和echarts不太熟悉,但是通过这个文件我学到了很多有用的知识。
- 山林公子2023-07-26文件中的代码示例和步骤说明都很详细,适合初学者入门。
- 乖巧是我姓名2023-07-26这个文件给了我很多关于flask和echarts使用可视化图表展示二手房统计数据的实用技巧。
菜鸟实战
- 粉丝: 1197
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功