title: Convert index number to int (Python)
body: <p><strong>EDIT:</strong> The .mean() function works just right:</p>
  
  <pre><code>renda['age'].mean()
  </code></pre>
  
  <p>I'm still not sure why the errors mentioned below and in the answers happened, but this helps as a shortcut.</p>
  
  <hr>
  
  <p>I got a DataFrame <code>renda</code> in which there's a column <code>age</code> and I need to get the mean of the ages. I wrote</p>
  
  <pre><code>t_age = renda['age'].sum()
  renda.index = renda.index.map(int) #intended solution
  last_id = renda.iloc(-1)
  print(t_age/last_id)
  </code></pre>
  
  <p>Trying to adapt the answers from <a href="https://stackoverflow.com/questions/35368645/pandas-change-df-index-from-float64-to-unicode-or-string">here</a>. It still doesn't work though and this error is raised:</p>
  
  <pre><code>TypeError: unsupported operand type(s) for /: 'int' and '_iLocIndexer'
  </code></pre>
  
  <p>What can I do to solve this? Thank you!</p>
  
  <hr>
  
  <p>@ScottBoston:</p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in na_op(x, y)
      657             result = expressions.evaluate(op, str_rep, x, y,
  --&gt; 658                                           raise_on_error=True, **eval_kwargs)
      659         except TypeError:
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/computation/expressions.py in evaluate(op, op_str, a, b, raise_on_error, use_numexpr, **eval_kwargs)
      210         return _evaluate(op, op_str, a, b, raise_on_error=raise_on_error,
  --&gt; 211                          **eval_kwargs)
      212     return _evaluate_standard(op, op_str, a, b, raise_on_error=raise_on_error)
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/computation/expressions.py in _evaluate_numexpr(op, op_str, a, b, raise_on_error, truediv, reversed, **eval_kwargs)
      121     if result is None:
  --&gt; 122         result = _evaluate_standard(op, op_str, a, b, raise_on_error)
      123 
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/computation/expressions.py in _evaluate_standard(op, op_str, a, b, raise_on_error, **eval_kwargs)
       63     with np.errstate(all='ignore'):
  ---&gt; 64         return op(a, b)
       65 
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in &lt;lambda&gt;(x, y)
       96                           default_axis=default_axis, reversed=True),
  ---&gt; 97         rtruediv=arith_method(lambda x, y: operator.truediv(y, x),
       98                               names('rtruediv'), op('/'), truediv=True,
  
  TypeError: unsupported operand type(s) for /: 'int' and 'str'
  
  During handling of the above exception, another exception occurred:
  
  TypeError                                 Traceback (most recent call last)
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in safe_na_op(lvalues, rvalues)
      681             with np.errstate(all='ignore'):
  --&gt; 682                 return na_op(lvalues, rvalues)
      683         except Exception:
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in na_op(x, y)
      667                 mask = notnull(x)
  --&gt; 668                 result[mask] = op(x[mask], y)
      669             else:
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in &lt;lambda&gt;(x, y)
       96                           default_axis=default_axis, reversed=True),
  ---&gt; 97         rtruediv=arith_method(lambda x, y: operator.truediv(y, x),
       98                               names('rtruediv'), op('/'), truediv=True,
  
  TypeError: unsupported operand type(s) for /: 'int' and 'str'
  
  During handling of the above exception, another exception occurred:
  
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-71-d5969a714aff&gt; in &lt;module&gt;()
        3 renda.index = renda.index.astype(int) #use astype to convert to int
        4 last_id = renda.iloc[-1] #Square brackets
  ----&gt; 5 print(t_age/last_id)
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in wrapper(left, right, name, na_op)
      719                 lvalues = lvalues.values
      720 
  --&gt; 721         result = wrap_results(safe_na_op(lvalues, rvalues))
      722         return construct_result(
      723             left,
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in safe_na_op(lvalues, rvalues)
      690                 if is_object_dtype(lvalues):
      691                     return libalgos.arrmap_object(lvalues,
  --&gt; 692                                                   lambda x: op(x, rvalues))
      693             raise
      694 
  
  pandas/_libs/algos_common_helper.pxi in pandas._libs.algos.arrmap_object (pandas/_libs/algos.c:31954)()
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in &lt;lambda&gt;(x)
      690                 if is_object_dtype(lvalues):
      691                     return libalgos.arrmap_object(lvalues,
  --&gt; 692                                                   lambda x: op(x, rvalues))
      693             raise
      694 
  
  /opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in &lt;lambda&gt;(x, y)
       95         rsub=arith_method(lambda x, y: y - x, names('rsub'), op('-'),
       96                           default_axis=default_axis, reversed=True),
  ---&gt; 97         rtruediv=arith_method(lambda x, y: operator.truediv(y, x),
       98                               names('rtruediv'), op('/'), truediv=True,
       99                               fill_zeros=np.inf, default_axis=default_axis,
  
  TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
  </code></pre>
  
  <hr>
  
  <p>@juanpa.arrivillaga:
  <a href="https://i.stack.imgur.com/61yst.png" rel="noreferrer"><img src="https://i.stack.imgur.com/61yst.png" alt="enter image description here"></a></p>