使用Python及R语言绘制简易数据分析报告

Pytohn实现

在python中有很多包可以实现绘制数据分析报告的功能,推荐两个较为方便的包:pandas-profiling 和 sweetviz 。

使用 pandas-profiling 包(功能全面)

这个包的个别依赖包与机器学习的 sklearn包的依赖包存在版本冲突,如已安装sklearn包的话可以在Anaconda中创建虚拟环境使用。

在Anaconda中创建python虚拟环境(创建了一个3.6版本,名为GGBoy的python虚拟环境):

bash 复制代码
conda create -n GGBoy python=3.6

Proceed([y]/n)? 中选择 y

创建虚拟环境成功后激活虚拟环境:

bash 复制代码
conda activate GGBoy

环境激活成功:

bash 复制代码
(GGBoy) C:\Users\114514>

在虚拟环境中安装pandas 包和pandas-profiling包:

bash 复制代码
conda install pandas
pip install pandas-profiling

绘制titandick数据集的数据报告,数据集下载地址:taitanic | Kaggle

在VSCode中建立一个拓展名.ipynb的jupyter notebook文件,内核选择刚才新建的虚拟环境:

使用pandas-profiling 包:

python 复制代码
from pandas_profiling import ProfileReport
import pandas as pd

# 使用pandas读取titandick的csv数据集
data = pd.read_csv('C:\\Users\\114514\\Desktop\\titandick.csv')
df = pd.DataFrame(data)

# 绘制数据分析报告
report = ProfileReport(df)  
report.to_file(output_file='report.html')

生成报告:

使用 sweetviz 包(最方便操作):

python 复制代码
import sweetviz as sv
import pandas as pd

# 使用pandas读取titandick的csv数据集
data = pd.read_csv('C:\\Users\\114514\\Desktop\\titandick.csv')
df = pd.DataFrame(data)

# 使用sweetviz包绘制数据分析报告
report = sv.analyze(df) 
report.show_html('report.html')

生成报告:

R语言实现

需要先下载R包 summarytools

R 复制代码
install.packages("summarytools")
R 复制代码
library(summarytools)

df <- read.csv("C:/Users/114514/Desktop/titandick.csv")
report <- dfSummary(df)  

html_report <- print(report, method = "render", include.row.numbers = FALSE, style = "grid")  

html_output <- paste(html_report, collapse = "\n")  

# 将合并后的HTML字符串写入文件  
cat(html_output, file = "report_GGBoy.html")

生成的数据分析报告:

相关推荐
用户8356290780511 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng81 天前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi1 天前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee1 天前
Python 中 `if x:` 到底在判断什么?
后端·python
ServBay1 天前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
闲云一鹤1 天前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi
Rockbean1 天前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
曲幽1 天前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
用户60648767188961 天前
国内开发者如何接入 Claude API?中转站方案实战指南(Python/Node.js 完整示例)
人工智能·python·api
只与明月听1 天前
RAG深入学习之Chunk
前端·人工智能·python