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%免费】
软件测试面试文档
我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。