Install any skill in seconds. Free to start, no credit card required.
Get Started Free →ecnu-icalk/Pandas分组操作保留原始多层索引
在对具有多层索引的Pandas DataFrame进行分组计算时,确保返回的结果保留原始的完整索引结构,而不是仅保留分组键。
Passed 23 of 23 test cases with the skill, and 21 of 23 without it.
2 fixed21 passed either way0 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 2 test cases the skill fixed. Same model, same prompt, with and without the skill.
Given a Pandas DataFrame with a MultiIndex (Store, Department), I need to find the 95th percentile of 'Sales' per 'Store'. I don't want the index to collapse or become regular columns. What is the code?
| Checked | Without skill | With skill |
|---|---|---|
| Uses transform with a lambda function calling quantile | Missed | Passed |
| Does not set as_index to False | Passed | Passed |
The instructions your model reads when the skill loads.
在对具有多层索引的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 的代码解决方案。test cases passed, vs 21 / 23 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.