擅长:python、mysql、java
<p><a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow noreferrer">cumcount</a>应该有效</p>
<pre class="lang-py prettyprint-override"><code>df.sort_values("Days Left") \
.assign(order=lambda x: x.groupby("ID").cumcount()) \
.sort_values(["order", "Days Left"]) \
.drop(columns="order")
</code></pre>