python - Python Pandas 在 csv 文件警告消息中添加新列
问题描述
我正在尝试在 CSV 文件中添加新列。
当我使用时df3['New header'] = None
,出现以下错误
`/Users/seven/PycharmProjects/Python3/venv/lib/python3.7/site-packages/pandas/core/indexing.py:966: 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[item] = s
所以我变成了df3.loc[index, 'New header'] = None
但是我又遇到了同样的错误。
有趣的部分是两种方式都成功添加了新列。
我怎样才能摆脱错误信息?
谢谢
解决方案
推荐阅读
- reactjs - reactstrap Collapse 没有出现在手机上
- javascript - 如何在 React.js 中使用 Font Awesome
- azure-sql-database - 有没有办法从 Azure SQL 数据库资源中获取分配的存储数据百分比指标以创建警报?
- c++ - 为什么当我尝试通过地址访问 Lambda 本地变量时出现访问冲突
- node.js - 在 CRA React 应用程序中构建构建脚本的正确方法是什么?
- java - 无法在 Eclipse 中创建新的 EJB 项目
- node.js - 错误 gyp ERR!堆栈错误:`C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe` failed with exit code: 1 while istalling Node on my project
- sas - 计算每个变量子集的唯一 ID 数
- delphi - Delphi - 更改菜单栏颜色
- java - 使用 gradle jar 文件查找主类时出现问题