python - 如何在 python 3 中删除此警告
问题描述
尝试使用熊猫降低和剥离python 3中的一列,但收到警告-正确的方法是什么,因此不会出现此警告
df["col1"] = df[["col1"]].apply(lambda x: x.str.strip())
df["col1"] = df[["col1"]].apply(lambda x: x.str.lower())
警告
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: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self[k1] = value[k2]
如何删除警告
解决方案
要摆脱此警告,请将其应用于系列而不是数据框。使用df[["col1"]]
正在创建一个新的数据框,然后您将其设置为列。如果您只是修改列就可以了。此外,我将两者链接在一起。
df["col1"] = df["col1"].str.strip().str.lower()
推荐阅读
- google-apps-script - 无法授予从谷歌电子表格中的孩子帐户运行脚本的访问权限
- mongodb - 尝试从 Spring Boot Docker 容器连接到 mongo Docker 容器时验证 MongoCredential 时出错?
- node.js - Angular 9 Node.js AWS - 添加 import AWS from 'aws-sdk' 后编译错误
- r - 如何将工作目录设置为子文件夹?
- html - iPhone 11 上的 apple-mobile-web-app-status-bar-style
- airflow - Google Cloud Composer:节省成本
- python - 在运行时更改 python 子类
- c# - 十进制值的规范化
- emgucv - EmguCV - 创建后垫不为空
- reactjs - Firebase Firestore 服务器时间戳而不将所有 Firebase 导入我的网络项目?