dataframe.loc赋值时产生告警

df1.loc[:,'data_index'] = df1.index

这个指令是哪里有问题?为什么总是有warning?

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
  self.obj[key] = _infer_fill_value(value)

loc我已经用了呀?看文档也没看明白。


df1.loc[:,'data_index'] = df1.index
这个loc里对列取值的时候 一般 [] 括起来

df1.loc[:,['data_index']] = df1.index