A value is trying to be set on a copy of a slice from a DataFrame
2017-10-05 21:20
609 查看
在为DataFrame对象新增一列数据时,报错“A value is trying to be set on a copy of a slice from a DataFrame”,原因是操作的数据不是原始数据,而是原始数据的视图。
解决方案:在新增列之前,显示复制原始数据。示例如下:
data4 = train_data[['uid', 'forward_count', 'like_count']].copy()
data4['forward_like_rate'] = data4['forward_count'] / (data4['like_count'] + 1)
解决方案:在新增列之前,显示复制原始数据。示例如下:
data4 = train_data[['uid', 'forward_count', 'like_count']].copy()
data4['forward_like_rate'] = data4['forward_count'] / (data4['like_count'] + 1)
相关文章推荐
- dataframe插入数据报错SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- Xcode4 布置Git环境Your working copy is out of date. Try pulling from the remote to get the latest change
- You may not call SetData on a resource while it is actively set on the GraphicsDevice. Unset it from
- 布置Git环境Your working copy is out of date. Try pulling from the remote to get the latest change
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- tesseract-ocr 出现 错误 Please make sure the TESSDATA_PREFIX environment variable is set to the parent d irectory of your "tessdata" directory.解决方案
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- 30.In which situation may the UNDO_RETENTION parameter be ignored, even if it is set to a value?
- Microsoft SQL Server 2008 R2 XML处理 One solution is to increase the number of characters retrieved from the server for XML data.
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- BUG: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
- 【随】Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack 问题解决。
- MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te