Find the end of the month of a Pandas DataFrame Series
<p>I have a series within a DataFrame that I read in initially as an object, and then need to convert it to a date in the form of <em>yyyy-mm-dd</em> where <em>dd</em> is the end of the month.</p>
<p>As an example, I have DataFrame <code>df</code> with a column <code>Date</code> as an object:</p>
<pre><code>...      Date    ...
...     200104   ...
...     200508   ...
</code></pre>
<p>What I want when this is all said and done is a date object:</p>
<pre><code>...      Date    ...
...  2001-04-30  ...
...  2005-08-31  ...
</code></pre>
<p>such that <code>df['Date'].item()</code> returns</p>
<pre><code>datetime.date(2001, 04, 30)
</code></pre>
<p>I've used the following code to get almost there, but all my dates are at the beginning of the month, not the end. Please advise.</p>
<pre><code>df['Date'] = pd.to_datetime(df['Date'], format=&quot;%Y%m&quot;).dt.date
</code></pre>
<p>Note: I've already imported Pandas (pd), and datetime (dt)</p>