gpt4 book ai didi

Python Pandas - 错误 : Can only compare identically-labeled Series objects

转载 作者:行者123 更新时间:2023-12-03 18:40:56 29 4
gpt4 key购买 nike

set df1["name"] = df2["name] if df1["id"] == df2["id]. 

两个数据帧的大小不同。我试图通过编写如下代码来实现这种行为:
   dtl['name'] = dtlLookUp[["name"]].loc[ dtlLookUp["id"] == (dtl["id"]) ]

但是,我收到错误:
ValueError: Can only compare identically-labeled Series objects

编辑 :

enter image description here

最佳答案

我的问题解决了。将它发布给可能遇到相同错误的任何其他人(因为我搜索了这个错误,但没有一个已经发布的解决方案对我有用,所以我只是改变了我解决问题的方向)。我将此问题视为左连接。

    psb = pd.merge(dtl, dtlLookUp, how='left', on=['id'])

附言把每个问题都标记下来是不礼貌的,只是因为你看不懂。但是,我相信该解决方案会对很多人有所帮助!!

关于Python Pandas - 错误 : Can only compare identically-labeled Series objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53089040/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com