擅长:python、mysql、java
<p>默认情况下,月频率(M)使用月末。如果你想要月初,你需要月初。(MS)</p>
<p>例如:</p>
<pre><code>np.random.seed(0)
timestamps = pd.DatetimeIndex(start='2020-01-01', end='2020-10-01', freq='1h')
df = pd.DataFrame({'Date': timestamps, 'data': np.random.randn(len(timestamps))})
df = df.groupby(pd.Grouper(key = 'Date', freq = 'MS')).max()
</code></pre>
<p>有关更多信息,请参见<a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases" rel="nofollow noreferrer">this table</a></p>