数据分析(二)自动生成分析报告

1. 报告生成思路概述

怎么快速一份简单的数据分析报告,注意这个报告的特点:

--网页版,可以支持在线观看或者分享HTML文件

--标题,动图,原始数据应有尽有

--支持交互,比如plotly交互画面,数据支持filter等

--各种展现方式,数字仪表盘,动图,数据表格,描述性文字等(音频,视频)

--以上报告没有写一行前端代码,完全自动生成。

--在数据分析的基础上,创建,生成,发布报告的时间大约2分钟

2. 报告生成步骤

--先安装datapane包(可以帮我们把我们上面的素材整合成一份网页报告,整合的函数就是Report):pip install datapane

--创建报告内容:比如原始数据df,动图fig1 和fig2

import plotly.express as px

df = px.data.gapminder()

fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country", size="pop", color="continent", hover_name="country", log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90],height=800)

fig2 = px.bar(df, x="continent", y="pop", color="continent", animation_frame="year", animation_group="country", range_y=[0,4000000000],height=800)

--利用datapane整合报告:上面的报告里面,fig采用Plot来生成报告,df采用DataTable生成报告,还有标题,数字仪表也是类似的方式生成。

import datapane as dp

report = dp.Report(

"# GDP分析报告",

"## 公众号:数据如琥珀",

dp.Group(dp.BigNumber(heading="中国", value=2),

dp.BigNumber(heading="GDP", value="17.7万亿"),columns=2,),

dp.Group(dp.Plot(fig, caption="GDP增长动画"),

dp.Plot(fig2, caption="GDP柱形图"),columns=2),

dp.DataTable(df, caption="原始数据"),

)

--生成html文件,save到本地:

report.save(path='report.html', open=True, formatting=dp.ReportFormatting(width=dp.ReportWidth.FULL))

3. 完整代码(code)

复制代码
import plotly.express as px
import datapane as dp

df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
                 size="pop", color="continent", hover_name="country",
                 log_x=True, size_max=55, range_x=[100, 20000], range_y=[25, 90], height=600)
fig2 = px.bar(df, x="continent", y="pop", color="continent", animation_frame="year", animation_group="country",
              range_y=[0, 1500000000], height=600)
report = dp.Report("# GDP分析报告", "##  title:数据分析二",
                   dp.Group(dp.BigNumber(heading="中国", value=2),
                            dp.BigNumber(heading="GDP", value="17.7万亿"), columns=2, ),
                   dp.Group(dp.Plot(fig, caption="GDP增长动画"),
                            dp.Plot(fig2, caption="GDP柱形图"), columns=2),
                   dp.DataTable(df, caption="原始数据"),
                   )
report.save(path='report.html', open=True, formatting=dp.Formatting(width=dp.Width.FULL))
相关推荐
阿里云大数据AI技术12 小时前
阿里云 EMR Serverless Spark: 面向 Data+AI 的高性能 Lakehouse 产品
大数据·人工智能·数据分析
饼干哥哥13 小时前
两句话,让Claude Code + Kimi K2 跑了3小时爬完17个竞品网站、做了一份深度市场数据分析报告
数据分析·agent·ai编程
杨超越luckly14 小时前
HTML应用指南:利用GET请求获取全国永辉超市门店位置信息
大数据·信息可视化·数据分析·html·argis·门店
2201_7530548919 小时前
应用回归分析,R语言,多元线性回归总结(中)
数据挖掘·回归·线性回归
吃手机用谁付的款20 小时前
基于hadoop的竞赛网站日志数据分析与可视化(下)
大数据·hadoop·python·信息可视化·数据分析
金牌服务刘1 天前
选择一个系统作为主数据源的优势与考量
大数据·数据分析·连续集成
神策技术社区2 天前
埋点采集之曝光
大数据·数据分析·客户端
陈哥聊测试2 天前
拖垮公司的真正元凶:低质量决策
数据分析·产品
小码编匠2 天前
C# 的西门子数控系统 OPCUA 数据采集开发从零入门
后端·数据分析·c#
北温凉2 天前
【论文阅读】基于注意力机制的冥想脑电分类识别研究(2025)
论文阅读·分类·数据挖掘