使用布尔掩码from
isin过滤df并从rhs
df分配所需的行值:
In [27]:df.loc[df.Name.isin(df1.Name), ['Nonprofit', 'Education']] = df1[['Nonprofit', 'Education']]dfOut[27]: Name Nonprofit Business Education0 X 1 1 01 Y 1 1 12 Z 1 0 13 Y 1 1 1[4 rows x 4 columns]

使用布尔掩码from
isin过滤df并从rhs
In [27]:df.loc[df.Name.isin(df1.Name), ['Nonprofit', 'Education']] = df1[['Nonprofit', 'Education']]dfOut[27]: Name Nonprofit Business Education0 X 1 1 01 Y 1 1 12 Z 1 0 13 Y 1 1 1[4 rows x 4 columns]