title: preventing pandas.DataFrame.loc from typecasting
body: <p>If we initialise a <code>pandas.DataFrame</code> where the type will be <code>int64</code>:  </p>
  
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  import pandas as pd 
  
  df1 = pd.DataFrame(np.arange(4).reshape((2,2)), columns=['one','two'])
  </code></pre>
  
  <p>and then typecast the first column to be <code>np.str</code> and look at the second row: </p>
  
  <p>(1)</p>
  
  <pre class="lang-py prettyprint-override"><code>df2 = df1.astype({'one':np.str}) 
  df2.loc[1,]
  </code></pre>
  
  <p><code>df2.loc[1,]</code> returns a pandas.Series having type <code>object</code>, with the elements' types preserved.</p>
  
  <p>However, if we typecast the second first column to be <code>np.float</code>      </p>
  
  <p>(2) </p>
  
  <pre class="lang-py prettyprint-override"><code>df3 = df1.astype({'one':np.float})
  df3.loc[1,]             
  </code></pre>
  
  <p><code>df3.loc[1,]</code> returns a pandas.Series having type <code>float64</code>, i.e. the int64 in column <code>'two'</code> was promoted to <code>float64</code>. </p>
  
  <p>Is there a way to ensure that <code>df.loc</code> always preserves type as in (1) avoid the behaviour in (2)?</p>
  
  <p>(And why would I care? Because ints can be passed as indexes, floats can't, and I'm slightly annoyed of having to recast objects because pandas decided that what I wanted as return value isn't what I had put into my dataframe originally) </p>