这几天刚学习Pandas,买了网课拿数据进行实战练习
建了一个DataFrame,准备增加一列新数据,赋值代码虽然正常运行了,但出现以下报错
In:
seasons = season(data2['月'])
reduced_features = data2[['前一天风速', '前一天最高温度', '每年该日最高温度均值', '当天最高温度']]
reduced_features['季节'] = seasons
Out:
<ipython-input-73-dd2221e85f95>:3: 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
reduced_features['季节'] = seasons
于是我改了一下,结果还是报错,报错还更长了……去
In:
#更改后,依然报错
reduced_features.loc[:,'季节'] = seasons
去看了一下报错里给的官网链接……还是没看懂。
最后新通过建变量来赋值,终于……终于不报错了