2024-05-18 06:52:26 发布
网友
DF1 |col1 | col2 | col3 | 12 v1 v12 3 v3 v13 5 v5 v14 7 v10 v15 DF2 |col2| col3| x1 y2 x2 y1 output DF1 |col1 | col2 | col3 | 12 x2 y1 3 v3 v13 5 v5 v14 7 x1 y2
我想将行7,12 inDF1设置为DF2的值,而不显式指定列
类似于DF1[7,12]=DF2的东西
您需要使用update
update
df2.index=[0,3]# change the index you want to update in df1, then just using update df1.update(df2) df1 Out[404]: col1 col2 col3 0 12 x1 y2 1 3 v3 v13 2 5 v5 v14 3 7 x2 y1
仅使用.loc语句:
.loc
DF1.loc[DF1.col1.isin([12,7]), 'col2'] = DF2.col2.values
返回:
>>> DF1 col1 col2 col3 0 12 x1 v12 1 3 v3 v13 2 5 v5 v14 3 7 x2 v15
您需要使用
update
仅使用
.loc
语句:返回:
相关问题 更多 >
编程相关推荐