擅长:python、mysql、java
<p>使用<code>np.where</code>即</p>
<pre><code>df2['Buy'] = np.where(df1['A']>54,'Buy',df2['Buy'])
df2['Sell'] = np.where(df1['A']<54,'Sell',df2['Sell'])
</code></pre>
<p>或<code>df.where</code>即</p>
<pre><code>df2['Buy'] = df2['Buy'].where(df1['A']<54,'Buy')
df2['Sell'] = df2['Sell'].where(df1['A']>54,'Sell')
</code></pre>
<p>输出:</p>
<pre>
Buy Hold Sell
Date
2011-08-26 0.0 0.0 Sell
2011-08-29 Buy 0.0 0.0
2011-08-30 Buy 0.0 0.0
2011-08-31 Buy 0.0 0.0
2011-09-01 Buy 0.0 0.0
2011-09-02 0.0 0.0 Sell
</pre>
<p>如果索引不相同,那么你必须按照@jezrael在他的解决方案中的建议重新编制索引。你知道吗</p>