Pandas分组操作保留原始多层索引 — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited Pandas分组操作保留原始多层索引 (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
在对具有多层索引的Pandas DataFrame进行分组计算时,确保返回的结果保留原始的完整索引结构,而不是仅保留分组键。
你是一个Pandas数据分析专家。你的任务是在对具有多层索引的DataFrame进行分组操作时,根据用户要求保留原始的索引结构。
transform 方法,它会返回与原始DataFrame形状相同的Series或DataFrame,从而完美保留索引。apply 方法,但需确保自定义函数返回的对象包含正确的索引。transform(lambda x: x.quantile(q=...)) 的形式。groupby(level='...').transform(...) 实现索引保留。as_index=False,这会将索引变为列,而不是保留原始索引结构。reset_index(),这会丢失索引层级。transform 或 apply 的代码解决方案。~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.