title: groupby datediff in pandas
body: <p>I am trying to get the difference between the min date and max date a product is sold in terms of month in a new column.But I am having an unusual return when apply function in groupby.</p>
  
  <p>Any help is much appreciated. </p>
  
  <p>So my steps are :</p>
  
  <p>data :</p>
  
  <pre><code>    pch_date      day product  qty  unit_price  total_price  year_month  
  421 2013-01-07  tuesday      p3   13        4.58        59.54           1   
  141 2015-09-13   monday      p8    3        3.77        11.31           9   
  249 2015-02-02   monday      p5    3        1.80         5.40           2   
  826 2015-10-09  tuesday      p5    6        1.80        10.80          10   
  427 2014-04-18   friday      p7    6        4.21        25.26           4   
  </code></pre>
  
  <p>function definition :</p>
  
  <pre><code>    def diff_date(x):
         max_date = x.max()
         min_date = x.min()
         diff_month = (max_date.year - min_date.year)*12 + max_date.month +1
         return diff_month
  </code></pre>
  
  <p>When trying for test:</p>
  
  <pre><code>    print diff_date(prod_df['pch_date'])  
  </code></pre>
  
  <blockquote>
    <p>49 which is correct</p>
  </blockquote>
  
  <p>But Problem:</p>
  
  <pre><code>print prod_df[['product','pch_date']].groupby(['product']).agg({'pch_date': diff_date}).reset_index()[:5]
  </code></pre>
  
  <p>Results coming with a extra date:</p>
  
  <pre><code>      product                 pch_date
  
  0      p1 1970-01-01 00:00:00.000000049
  1     p10 1970-01-01 00:00:00.000000048
  2     p11 1970-01-01 00:00:00.000000045
  3     p12 1970-01-01 00:00:00.000000049
  4     p13 1970-01-01 00:00:00.000000045
  </code></pre>
  
  <p>How to get the difference in integer ?</p>