擅长:python、mysql、java
<h3>使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.resample.html" rel="nofollow noreferrer">^{<cd1>}</a>+<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.resample.Resampler.sum.html" rel="nofollow noreferrer">^{<cd2>}</a>+<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.query.html" rel="nofollow noreferrer">^{<cd3>}</a>:</h3>
<pre><code>df_out = (df.assign(Date=pd.to_datetime(df['Date'], format='%b-%Y'))
.resample('Q', on='Date', kind='period')
.sum()
.query('Number != 0')
).reset_index()
</code></pre>
<p><strong>结果:</strong></p>
<pre><code>print(df_out)
Date Number
0 2017Q1 150
1 2020Q2 130
2 2021Q3 70
</code></pre>