dtypes changed when initialising a new DataFrame from another one
<p>Let's say that I have a DataFrame df1 with 2 columns: <code>a</code> with dtype <code>bool</code> and <code>b</code> with dtype <code>int64</code>. When I initialise a new DataFrame (<code>df1_bis</code>) from <code>df1</code>, columns <code>a</code> and <code>b</code> are automatically converted into objects, even if I force the dtype of <code>df1_bis</code>:</p>

<pre><code>In [2]: df1 = pd.DataFrame({"a": [True], 'b': [0]})
Out[3]:
      a  b
0  True  0

In [4]: df1.dtypes
Out[4]:
a     bool
b    int64
dtype: object

In [5]: df1_bis = pd.DataFrame(df1.values, columns=df1.columns,     dtype=df1.dtypes)
Out[6]:
      a  b
0  True  0

In [7]: df1_bis.dtypes
Out[7]:
a    object
b    object
dtype: object
</code></pre>

<p>Is there something I'm doing wrong with the <code>dtype</code> argument of DataFrame? </p>

<p>For me works:</p>

<pre><code>df1_bis = pd.DataFrame(df1, columns=df1.columns, index=df1.index)
#df1_bis = pd.DataFrame(df1)

print (df1_bis)
      a  b
0  True  0

print (df1_bis.dtypes)
a     bool
b    int64
dtype: object
</code></pre>

<p>But I think better is use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.copy.html" rel="nofollow"><code>copy</code></a>:    </p>

<pre><code>df1_bis = df1.copy()
</code></pre>

<p>If you want use <code>dtype</code>, you need works with <code>Series</code> because parameter <code>dtype</code> in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html" rel="nofollow"><code>DataFrame</code></a> is for all columns:</p>

<pre><code>df1_bis = pd.DataFrame({'a':pd.Series(df1.a.values, dtype=df1.a.dtypes),
                        'b':pd.Series(df1.b.values, dtype=df1.b.dtypes)}
                       , index=df1.index)

print (df1_bis)
      a  b
0  True  0

print (df1_bis.dtypes)
a     bool
b    int64
dtype: object
</code></pre>

<hr>

<pre><code>df = pd.DataFrame({"a": [1,5], 'b': [0,4]}, dtype=float)
print (df)
     a    b
0  1.0  0.0
1  5.0  4.0

print (df.dtypes)
a    float64
b    float64
dtype: object
</code></pre>

python pandas dataframe casting multiple-columns