擅长:python、mysql、java
<p>使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.nth.html" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>In [683]: date1 = df.groupby('product').Date.nth(-2).tolist()
In [684]: date2 = df.groupby('product').Date.nth(-3).tolist()
In [685]: date1
Out[685]: ['201401', '201402']
In [686]: date2
Out[686]: ['202003', '201903']
</code></pre>