在pandas中使用.loc后仍获得SettingWithCopyWarning警告

2024-06-07 04:28:26 发布

您现在位置:Python中文网/ 问答频道 /正文

df_masked.loc[:, col] = df_masked.groupby([df_masked.index.month, df_masked.index.day])[col].\
            transform(lambda y: y.fillna(y.median()))

即使使用了.loc,我也能得到foll。错误,我该怎么解决?

Anaconda\lib\site-packages\pandas\core\indexing.py:476: 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: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self.obj[item] = s

Tags: thepandasdfindexvaluetransformcolloc