We want you to add an extra method, quantile_clip, to pandas.Series and pandas.DataFrame.
quantile_clip has a couple of modes:
my_series.quantile_clip(lower=0.02)
clip the lowest 2% of values up to the 2%ile value.my_series.quantile_clip(upper=0.98)
clip the highest 98% of values down to the 98%ile value.my_series.quantile_clip(lower=0.02, upper=0.98)
do both.
这道题要求为 pandas 的 Series 和 DataFrame 增加一个 quantile_clip 方法,本质上是按分位数对数据做裁剪(clip)。给定 lower 和 / 或 upper 参数时,需要先计算对应分位点,再把低于下界的值抬高到下界,把高于上界的值压低到上界。题目重点在于正确使用分位数、对不同参数组合分别处理,并保持与 pandas 风格一致的接口设计。
正文完