Parse Pandas Column to date from string with dashes
<p>Trying to parse pandas columns <code>df['day']</code> into datetime type. Values are current written as strings, such as: <code>2016-9-1</code>. This corresponds to Year-Month-Day.</p>

<p>I'm following the formatting from this page:
<a href="http://strftime.org/" rel="nofollow">http://strftime.org/</a></p>

<p>I initially tried to use</p>

<pre><code>pd.to_datetime(df['day'], format="%Y-%m-%d")
</code></pre>

<p>but got the error</p>

<pre><code>ValueError: time data 'day' does match format specified
</code></pre>

<p>I figured the problem was that day and month weren't zero, padded, so changed it to:</p>

<pre><code>pd.to_datetime(df['day'], format="%Y-%-m-%-d")
</code></pre>

<p>I'm using <code>%-m</code> and <code>%-d</code>, since both correspond to non-zero-padded (decimal) numbers.</p>

<p>Getting different error:</p>

<pre><code>ValueError: '-' is a bad directive in format '%Y-%-m-%-d'
</code></pre>

<p>Shouldn't I be following the formatting convention from <a href="http://strftime.org/" rel="nofollow">http://strftime.org/</a>, am I missing something?</p>