擅长:python、mysql、java
<p>在[27]中:
这是正确的</p>
<pre><code>df.loc[df.Name.isin(df1.Name), ['Nonprofit', 'Education']] = df1[['Nonprofit', 'Education']].values
df
Out[27]:
Name Nonprofit Business Education
0 X 1 1 0
1 Y 1 1 1
2 Z 1 0 1
3 Y 1 1 1
</code></pre>
<p>[4行x 4列]</p>
<p>只有当df1中的所有行都存在于df中时,上述操作才起作用。换句话说,df应该是df1的超集</p>
<p>如果您在df1中有一些与df不匹配的行,您应该遵循以下步骤</p>
<p>换句话说,df不是df1的超集:</p>
<pre><code>df.loc[df.Name.isin(df1.Name), ['Nonprofit', 'Education']] =
df1.loc[df1.Name.isin(df.Name),['Nonprofit', 'Education']].values
</code></pre>