且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python数据框未在索引上合并

更新时间:2023-08-29 14:05:28

嗯,从您的问题来看,似乎您正在尝试合并索引,但是您将它们视为列?尝试稍微更改合并代码-

Hmm, from looking at your problem, it seems like you're trying to merge on the indexes, but you treat them as columns? Try changing your merge code a bit -

player_runs.merge(matches_played_by_players,
                  left_index=True,
                  right_index=True,
                  how='left')

此外,请确保两个索引均为相同类型(在这种情况下,请考虑 str int?)

Furthermore, make sure that both indexes are of the same type (in this case, consider strint?)

player_runs.index = player_runs.index.astype(int)

然后

matches_played_by_players.index = matches_played_by_players.index.astype(int)