首页 > 解决方案 > 设置 nan 值数据框时的警告

问题描述

想象一下,您有以下 df:

dffinalselection= pd.DataFrame(np.array([[1, np.nan, np.nan], [4, 5, 6], [7, 8, 9]]),
                   columns=['description#1', 'Party', 'Factuurdatum'])

使用此代码,我试图填充 nan 值:

dffinalselection.loc[dffinalselection['description#1'].isna() == True, 'description#1'] = dffinalselection['Party'] +  " " dffinalselection['Factuurdatum']

但是,收到警告:

c:\python38\lib\site-packages\pandas\core\indexing.py:1745: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  isetter(ilocs[0], value)

如何减轻此警告?

看起来不太好看。

请帮忙!

标签: pythonpandasnumpy

解决方案


推荐阅读