AttributeError: ‘DataFrame‘ object has no attribute ‘set_value‘怎么修改问题的解决
在jupyternotebook中运行:
def remplacement_df_keywords(df, dico_remplacement, roots = False):df_new = df.copy(deep = True)for index, row in df_new.iterrows():chaine = row['plot_keywords']if pd.isnull(chaine): continuenouvelle_liste = []for s in chaine.split('|'): clef = PS.stem(s) if roots else sif clef in dico_remplacement.keys():nouvelle_liste.append(dico_remplacement[clef])else:nouvelle_liste.append(s) df_new.set_value(index, 'plot_keywords', '|'.join(nouvelle_liste))return df_newdf_keywords_cleaned = remplacement_df_keywords(df_duplicate_cleaned, keywords_select,roots = True)
出现报错信息, DataFrame' object has no attribute 'set_val,是因为DataFrame 对象没有 set_value 方法,因为我正在使用 Pandas 的较新版本。
在 Pandas 1.0.0 及以上版本中,set_value 方法已经被弃用并移除了。
将df_new.set_value(index, 'plot_keywords', '|'.join(nouvelle_liste))替代为df_new.loc[index, 'plot_keywords'] = '|'.join(nouvelle_liste)可以通过。