55 lines
1.7 KiB
Markdown
55 lines
1.7 KiB
Markdown
---
|
||
title: "Pandas"
|
||
type: entity
|
||
tags: [python, data-analysis, library]
|
||
sources: [testing-test-results-analyzer]
|
||
last_updated: 2026-04-28
|
||
---
|
||
|
||
## Aliases
|
||
- pandas
|
||
- pandas DataFrame
|
||
- pandas Series
|
||
|
||
## Definition
|
||
|
||
Pandas 是 Python 的核心数据分析库,提供高性能、易用的数据结构和数据分析工具,在测试结果分析中用于读取、处理和转换测试数据。
|
||
|
||
## Usage in Test Analysis (from TestResultsAnalyzer)
|
||
|
||
```python
|
||
import pandas as pd
|
||
|
||
# 读取测试结果数据
|
||
self.test_results = pd.read_json(test_results_path)
|
||
|
||
# 分析测试覆盖缺口
|
||
for file_path, file_coverage in uncovered_files.items():
|
||
if file_coverage['lines']['pct'] < 80:
|
||
gap_analysis.append({
|
||
'file': file_path,
|
||
'coverage': file_coverage['lines']['pct'],
|
||
'risk_level': self._assess_file_risk(file_path, file_coverage)
|
||
})
|
||
```
|
||
|
||
## Core Data Structures
|
||
|
||
- **Series**:一维标记数组,类似带索引的列。
|
||
- **DataFrame**:二维表格数据结构,类似电子表格或 SQL 表。
|
||
- **Panel**:三维数据结构(已弃用)。
|
||
|
||
## Key Methods for Test Analysis
|
||
|
||
- `read_json()` / `read_csv()`:加载测试结果数据。
|
||
- `groupby()`:按类别(功能/性能/安全/集成)分组分析。
|
||
- `describe()`:生成描述性统计摘要。
|
||
- `merge()` / `join()`:跨数据源关联分析。
|
||
|
||
## Connections
|
||
|
||
- [[Statistical-Analysis]]:与 scipy 配合进行统计分析。
|
||
- [[Quality-Metrics]]:Pandas 是质量指标计算的基础数据处理工具。
|
||
- [[Test-Coverage-Analysis]]:Pandas 用于覆盖率数据处理和缺口分析。
|
||
- [[Failure-Pattern-Analysis]]:Pandas 用于失败数据的分组和趋势分析。
|