title: Python 3: "TypeError: cannot astype a datetimelike from [datetime64[ns]] to [int32]" - Jupyter Notebook
body: <p>Running into an issue with a jupyter notebook project I'm trying to get working on my Windows 10 machine, running Python 3. I get the mentioned error from this function:</p>
  
  <pre><code>buy_per_min = (buy
                 .groupby([pd.Grouper(key='timestamp', freq='Min'), 'price'])
                 .shares
                 .sum()
                 .apply(np.log)
                 .to_frame('shares')
                 .reset_index('price')
                 .between_time(market_open, market_close)
                 .groupby(level='timestamp', as_index=False, group_keys=False)
                 .apply(lambda x: x.nlargest(columns='price', n=depth))
                 .reset_index())
  buy_per_min.timestamp = buy_per_min.timestamp.add(utc_offset).astype(int)
  buy_per_min.info()
  </code></pre>
  
  <p>The issue is in the
  <code>buy_per_min.timestamp = buy_per_min.timestamp.add(utc_offset).astype(int)</code> line, but I don't fully understand why I'm getting it. This is the full traceback:</p>
  
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-28-396768b710c8&gt; in &lt;module&gt;()
       10                .apply(lambda x: x.nlargest(columns='price', n=depth))
       11                .reset_index())
  ---&gt; 12 buy_per_min.timestamp = buy_per_min.timestamp.add(utc_offset).astype(int)
       13 buy_per_min.info()
  
  ~\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py in astype(self, dtype, copy, errors, **kwargs)
     5689             # else, only a single dtype is given
     5690             new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors,
  -&gt; 5691                                          **kwargs)
     5692             return self._constructor(new_data).__finalize__(self)
     5693 
  
  ~\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\internals\managers.py in astype(self, dtype, **kwargs)
      529 
      530     def astype(self, dtype, **kwargs):
  --&gt; 531         return self.apply('astype', dtype=dtype, **kwargs)
      532 
      533     def convert(self, **kwargs):
  
  ~\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\internals\managers.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
      393                                             copy=align_copy)
      394 
  --&gt; 395             applied = getattr(b, f)(**kwargs)
      396             result_blocks = _extend_blocks(applied, result_blocks)
      397 
  
  ~\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\internals\blocks.py in astype(self, dtype, copy, errors, values, **kwargs)
      532     def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
      533         return self._astype(dtype, copy=copy, errors=errors, values=values,
  --&gt; 534                             **kwargs)
      535 
      536     def _astype(self, dtype, copy=False, errors='raise', values=None,
  
  ~\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\internals\blocks.py in _astype(self, dtype, **kwargs)
     2137 
     2138         # delegate
  -&gt; 2139         return super(DatetimeBlock, self)._astype(dtype=dtype, **kwargs)
     2140 
     2141     def _can_hold_element(self, element):
  
  ~\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\internals\blocks.py in _astype(self, dtype, copy, errors, values, **kwargs)
      631 
      632                     # _astype_nansafe works fine with 1-d only
  --&gt; 633                     values = astype_nansafe(values.ravel(), dtype, copy=True)
      634 
      635                 # TODO(extension)
  
  ~\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\dtypes\cast.py in astype_nansafe(arr, dtype, copy, skipna)
      644         raise TypeError("cannot astype a datetimelike from [{from_dtype}] "
      645                         "to [{to_dtype}]".format(from_dtype=arr.dtype,
  --&gt; 646                                                  to_dtype=dtype))
      647 
      648     elif is_timedelta64_dtype(arr):
  
  TypeError: cannot astype a datetimelike from [datetime64[ns]] to [int32]
  </code></pre>
  
  <p>Is there some kind of conversion I need to do to the timestamp info, and what might it look like? Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>There has been a similar question asked before, which I already read, but fail to see how that can be applied to my issue and would love an explanation if someone else knew. It can be found here:</p>
  
  <p><a href="https://stackoverflow.com/questions/40453744/pandas-dataframe-cannot-astype-a-datetimelike-from-datetime64ns-to-float">Pandas DataFrame - &#39;cannot astype a datetimelike from [datetime64[ns]] to [float64]&#39; when using ols/linear regression</a></p>