objectif
Calculer ranks et pourcentages de rang par groupe.
code minimal
import pandas as pd
df = pd.DataFrame({"g":["a","a","b","b"], "x":[10,30,20,40]})
print(df.groupby("g")["x"].rank(pct=True).tolist())
utilisation
import pandas as pd
s = pd.Series([100,50,75])
print(s.rank(method="dense").tolist())
variante(s) utile(s)
import pandas as pd
df = pd.DataFrame({"g":["a","a","b","b"], "x":[10,30,20,40]})
pr = df.groupby("g")["x"].rank(pct=True)
print(pr.groupby(df["g"]).mean().round(2).to_dict())
notes
pct=Truedonne le rang relatif (0..1).