title: Replacing datetime conditionally - python
body: <p>I have a 'Posting Date' column in the dataframe in the format of <code>'2017-03-01'</code>. The type is <code>&lt;datetime64&gt;[ns]</code>. And I want to change the value if it is after '2017-03-31' to '2017-03-31', and all others remain unchanged.</p>
  
  <p>When I type <code>df['Posting Date']&gt;'2017-03-31'</code>,it can correctly show me all the rows where the condition is met. So I guess the date filtering function works.</p>
  
  <p>However, when I used <code>numpy.where</code> to write the condition as this:</p>
  
  <pre><code>df['Posting Date'] = np.where(df['Posting Date']&gt;'2017-03-31','2017-03-31,'df['Posting Date'])
  </code></pre>
  
  <p>it incurrs an <code>invalid type promotion</code> error.</p>
  
  <p>I also tried <code>df.loc</code> and the same error occers. </p>
  
  <pre><code>df.loc[df['Posting Date']&gt;'2017-03-31','Posting Date']='2017-03-31'
  </code></pre>
  
  <p><code>ValueError: invalid literal for int() with base 10: '2017-03-31'</code></p>
  
  <p>I'm wondering why the error occurs. How can I replace date correctly? Whatever method which works is fine.</p>