我已经搜索了很多并阅读了文档,但我仍然不确定为什么我会收到此警告。我按列引用DataFrame并且仅在单个级别引用。我没有在此代码中设置任何内容。
这是错误:
afr.py:51: 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 the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
list_deciles.append(iter_summary(df[df['decile'] == s]))
以下是代码段:
def qcut_variable(df, variable):
df['decile']=pd.qcut(df[variable],10)
df_group_by = df.groupby('decile')
list_deciles = []
for s in df['decile'].cat.categories:
list_deciles.append(iter_summary(df[df['decile'] == s]))
df_deciles = pd.DataFrame(list_deciles)
return df_deciles