You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pd.concat报错TypeError: concat() got an unexpected keyword argument 'join_axes'如何解决

问题原因

  • join_axes 是 pandas 0.25 版本的废弃参数,在 pandas 1.0 及之后的正式版本中已被彻底移除,因此调用 pd.concat() 时传入该参数会抛出不存在该关键字参数的报错。
  • 你当前代码的逻辑是从原数据帧拆分出风格字段做独热编码后再拼接回原表,两个待拼接对象的索引天然同源对齐,不需要额外指定对齐规则。

修复方案

直接删除代码中 join_axes 参数即可正常运行,修正后代码如下:

Genre = movie_ratings_selected_df['Genres']
Genre = Genre.str.get_dummies().add_prefix('Genres_')
movie_ratings_genres_df = pd.concat(
    [movie_ratings_selected_df.drop(
        ['Genres'],
        axis=1
    ),
     Genre],
    axis=1
)
movie_ratings_genres_df.head()

如果后续遇到需要实现原 join_axes 指定索引对齐的通用场景,可以提前用 reindex 方法处理待拼接的对象,写法如下:

movie_ratings_genres_df = pd.concat(
    [
        movie_ratings_selected_df.drop(['Genres'], axis=1),
        # 提前按指定索引重对齐要拼接的对象
        Genre.reindex(movie_ratings_selected_df.index)
    ],
    axis=1
)

内容的提问来源于stack exchange,提问作者JBelo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 09:57:04