title: How to subtract month correctly in Pandas
body: <p>My dataframe has two columns. When I subtract them to get the month in between, I got some weird numbers. Here is an example:</p>
  
  <pre><code>test = pd.DataFrame({'reg_date': [datetime(2017,3,1), datetime(2016,9,1)], 
                   'leave_date':[datetime(2017,7,1), datetime(2017,6,1)]})
  test['diff_month'] = test.leave_date.dt.month - test.reg_date.dt.month
  test
  </code></pre>
  
  <p>The output:</p>
  
  <p><a href="https://i.stack.imgur.com/sQrZx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sQrZx.png" alt="enter image description here"></a></p>
  
  <p>If a user's register_date is last year, I get a negative number (also incorrect as well).</p>
  
  <p>What operations should I perform to get the correct time difference in month between two datetime column?</p>
  
  <hr>
  
  <p>Update: I changed the example a bit so it reflects more about the issue I am facing. Don't down vote so fast guys.</p>
  
  <p>A hack I did to fix this is:</p>
  
  <pre><code>test['real_diff'] = test.diff_month.apply(lambda x: x if x &gt; 0 else 12+x)
  </code></pre>
  
  <p>I don't like the hack so I am curious if there is any other way of doing it.</p>