我有一个包含流域 ID 和土地覆盖类别的表格:
WatershedID LandCover
2 Corn
8 Corn
2 Soy
8 Soy
和一个单独的查找表,其中包含每个流域/土地覆盖组合的面积:
WatershedID Corn Soy
2 14 1
3 2 14
5 18 8
7 21 2
8 6 31
我想做的是将一列附加到包含查找表中相应行/列值的第一个表,如下所示:
WatershedID LandCover Area
2 Corn 14
8 Corn 6
2 Soy 1
8 Soy 31
我已经设法通过使用 for 循环迭代来做到这一点:
areas = []
for watershed_id, land_cover in tableA.iterrows():
areas.append(tableB.loc[watershed_id][land_cover]
但考虑到我桌子的大小,这很慢。有没有更快的方法来做到这一点而不涉及迭代?我一直在尝试使用 MultiIndexing 和数据透视表,但到目前为止没有任何效果。