我有两个数据帧df_source和df_dest,如下所示:
>>> df_source = pd.read_csv('Product_Lookup.csv')
>>> df_source
ProdCode ProdName ProdUPC ProdQty
0 131 Apple 1100034030045 1
1 320 Bookshelf 2222200209090 1
2 420 Comic Book 4449435895489 5
3 511 Drillbits 5558493958393 10
4 55 Eggs 6660001110005 20
5 12 Fish food 9099910002776 50
>>> df_dest = pd.read_csv('Product_Dest.csv')
>>> df_dest
CustName ProdCode ProdName ProdUPC ProdQty
0 Fred 12 nan nan nan
1 Sanjay 131 nan nan nan
2 Rita 55 nan nan nan
3 Steph 511 nan nan nan
4 Hannah 55 nan nan nan
5 Roger 131 nan nan nan
对于在处理功能中处理多列种群的熊猫,我还没有看到这里的问题。
我正在尝试通过将df_dest.loc[:,['ProdName','ProdUPC','ProdQty']]
与df_dest['ProdCode']
匹配来填充df_source['ProdCode']
。
我可以用iterrows()
来做到这一点,但希望更快,更优雅。任何帮助都非常感谢!