<p>我遇到了一个奇怪的问题(或者说是有意的?)其中,<code>combine_first</code>或<code>update</code>导致存储为<code>bool</code>的值被上推到<code>float64</code>s中,如果提供的参数没有提供布尔列。在</p>
<p>ipython中的工作流示例:</p>
<pre><code>In [144]: test = pd.DataFrame([[1,2,False,True],[4,5,True,False]], columns=['a','b','isBool', 'isBool2'])
In [145]: test
Out[145]:
a b isBool isBool2
0 1 2 False True
1 4 5 True False
In [147]: b = pd.DataFrame([[45,45]], index=[0], columns=['a','b'])
In [148]: b
Out[148]:
a b
0 45 45
In [149]: test.update(b)
In [150]: test
Out[150]:
a b isBool isBool2
0 45 45 0 1
1 4 5 1 0
</code></pre>
<p>这是不是意味着<code>update</code>函数的行为?我认为,如果没有指定任何内容,<code>update</code>不会扰乱其他列。在</p>
<hr/>
<p><strong>编辑</strong>:我开始多做一些修改。情节越来越复杂。如果我在运行<code>test.update(b)</code>之前再插入一个命令:<code>test.update([])</code>,那么布尔行为会以上推为<code>objects</code>的数字为代价。这也适用于DSM的简化示例。在</p>
<p>基于<a href="https://github.com/pydata/pandas/blob/master/pandas/core/frame.py#L3830" rel="nofollow">panda's source code</a>,类似reindex的方法创建了一个dtype <code>object</code>的数据帧,而类似reindex的方法<code>b</code>创建了一个dtype <code>float64</code>的数据帧。由于<code>object</code>更为通用,因此后续的操作将使用bool。不幸的是,在数值列上运行<code>np.log</code>将失败,并返回<code>AttributeError</code>。在</p>