python 生成报表常用的10个脚本

900 篇文章 28 订阅
871 篇文章 0 订阅

2024软件测试面试刷题,这个小程序(永久刷题),靠它快速找到工作了!(刷题APP的天花板)_软件测试刷题小程序-CSDN博客文章浏览阅读3.4k次,点赞86次,收藏15次。你知不知道有这么一个软件测试面试的刷题小程序。里面包含了面试常问的软件测试基础题,web自动化测试、app自动化测试、接口测试、性能测试、自动化测试、安全测试及一些常问到的人力资源题目。最主要的是他还收集了像阿里、华为这样的大厂面试真题,还有互动交流板块……_软件测试刷题小程序​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502icon-default.png?t=N7T8https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502

1. 基本数据统计报表

场景: 生成包含数据基本信息(计数、均值、标准差等)的报表。

import pandas as pd

# 加载数据

df = pd.read_csv('data.csv')

# 生成描述性统计报表

report_stats = df.describe()

print(report_stats)‍

2. 数据透视表

场景: 利用透视表分析不同维度下的数据汇总。

pivot_table = pd.pivot_table(df, values='Sales', index=['Year', 'Category'], aggfunc=np.sum)

print(pivot_table)‍

3. 条形图展示分类数据

场景: 不同产品的销售量比较。

import matplotlib.pyplot as plt

product_sales = df['Product'].value_counts()

product_sales.plot(kind='bar')

plt.title('Product Sales Comparison')

plt.xlabel('Product')

plt.ylabel('Sales Count')

plt.show()‍

4. 饼图展示占比

场景: 客户来源渠道占比。

channel_counts = df['Source_Channel'].value_counts(normalize=True)

channel_counts.plot(kind='pie', autopct='%1.1f%%')

plt.title('Customer Source Channel Distribution')

plt.show()‍

5. 折线图展示趋势

场景: 每月销售额趋势。

df['Month'] = df['Date'].dt.month

monthly_sales = df.groupby('Month')['Sales'].sum()

monthly_sales.plot(kind='line')

plt.title('Monthly Sales Trend')

plt.xlabel('Month')

plt.ylabel('Total Sales')

plt.show()‍

6. 热力图分析变量间关系

场景: 相关性矩阵可视化。

import seaborn as sns

correlation_matrix = df.corr()

sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm')

plt.title('Correlation Matrix Heatmap')

plt.show()‍

7. 箱线图识别离群点

场景: 检测销售数据中的异常值。

sns.boxplot(x=df['Sales'])

plt.title('Sales Data Outlier Detection')

plt.show()‍

8. 分组柱状图

场景: 不同年份各产品类别的销售对比。

sns.catplot(x='Category', y='Sales', hue='Year', data=df, kind='bar')

plt.title('Annual Category Sales Comparison')

plt.show()‍

9. 自定义PDF报告

场景: 生成包含图表和表格的综合PDF报告。

from reportlab.lib.pagesizes import letter, landscape

from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, Table, TableStyle

# 简化的PDF报告生成示例

doc = SimpleDocTemplate("report.pdf", pagesize=landscape(letter))

story = []

# 添加标题

story.append(Paragraph("Sales Report", style))

# 添加图片(这里假设你有图片处理逻辑)

img_data = open('chart.png', 'rb').read()

img = Image(img_data, width=400, height=300)

story.append(img)

# 添加表格(使用Pandas DataFrame转换)

table_data = [df.columns.tolist()] + df.values.tolist()

t = Table(table_data)

t.setStyle(TableStyle([('BACKGROUND', (0,0), (-1,0), '#CCCCCC')] + [('TEXTCOLOR',(0,0),(-1,0), '#000000')] + [('ALIGN',(0,0),(-1,-1),'CENTER')] + [('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold')] + [('FONTSIZE', (0,0), (-1,0), 14)]))

story.append(t)

doc.build(story)‍

10. 交互式仪表板(使用Plotly或Dash)

场景: 创建可交互的网页仪表板展示多维度数据。

import plotly.express as px

import dash

import dash_core_components as dcc

import dash_html_components as html

from dash.dependencies import Input, Output

app = dash.Dash(__name__)

app.layout = html.Div([

    dcc.Dropdown(id='year-selector', options=[{'label': i, 'value': i} for i in df['Year'].unique()], value=df['Year'].min()),

    dcc.Graph(id='sales-graph')

])

@app.callback(

    Output('sales-graph', 'figure'),

    Input('year-selector', 'value'))

def update_graph(selected_year):

    filtered_df = df[df['Year'] == selected_year]

    fig = px.bar(filtered_df, x='Category', y='Sales', title=f'Sales by Category in {selected_year}')

    return fig

if __name__ == '__main__':

    app.run_server(debug=True)‍

行动吧,在路上总比一直观望的要好,未来的你肯定会感谢现在拼搏的自己!如果想学习提升找不到资料,没人答疑解惑时,请及时加入群: 759968159,里面有各种测试开发资料和技术可以一起交流哦。

最后: 下方这份完整的软件测试视频教程已经整理上传完成,需要的朋友们可以自行领取【保证100%免费】

​​​软件测试面试文档

我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

在这里插入图片描述

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值