[Python Debug] SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
I Got a SettingWithCopyWarning when I ran the following code:
tmp=date[date['date'].isnull().values==True]
tmp['date']=tmp['text'].str.extract(regex2,re.VERBOSE)
The details of the Warning are :
/Users/monica/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:23: 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
Then I got the inspiration from
https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas
The
SettingWithCopyWarningwas created to flag potentially confusing "chained" assignments such as the following, which don't always work as expected, particularly when the first selection returns a copy.df[df['A'] > 2]['B'] = new_val # new_val not set in dfThe warning offers a suggestion to rewrite as follows:
df.loc[df['A'] > 2, 'B'] = new_valOr you can safely disable this new warning with the following assignment.
pd.options.mode.chained_assignment = None # default='warn'
Since we copied the dataframe firstly, there are some other options.
You can set the
is_copyflag toFalse, which will effectively turn off the check, for that object:tmp.is_copy = FalseOr explicitly copy then no further warning will happen.
In my case, the problem was solved by add .copy( ) method while defining tmp, i.e.,
tmp=date[date['date'].isnull().values==True].copy()
tmp['date']=tmp['text'].str.extract(regex2,re.VERBOSE)
[Python Debug] SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.的更多相关文章
- 问题解决:SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
转载:y小川 SettingWithCopyWarning 解决方案 问题场景:我在读取csv文件之后,因为要新增一个特征列并根据已有特征修改新增列的值,结果在修改的时候就碰到了SettingWith ...
- [pandas] SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
转载自https://blog.csdn.net/blackyuanc/article/details/77892784 问题场景: 在读取CSV文件后,在新增一个特征列并根据已有特征修改 ...
- 极简Python DeBug工具——PySnooper
DeBug Python 代码的方式有很多种?比如: (1)设置断点 (2)print函数 (3)... 本文要介绍的是一个新开源的项目PySnooper ,只要给有疑问的代码加上装饰器,各种信息一目 ...
- Python Debug工具
最近在github上冒出了一个python的debug神器PySnooper,号称在debug时可以消灭print.那么该工具有哪些优点呢,如何使用该工具呢.本文就介绍该工具的优缺点和使用方式. 前言 ...
- python Debug 单步调试
一直犯愁的是python的调试,曾经写c都是编译完了用gdb直接调试了,轻松愉快.如今遇到这么一个解释型的程序.不知道怎么办了.用log吧,有时就是一个小程序,不想写这么多代码.打屏吧.有时屏幕翻得快 ...
- python debug open_files
主要是遇到 Error 24, too many open files. 下面这种方法可以debug打开了哪些文件. import __builtin__ openfiles = set() oldf ...
- python debug小技巧&&工程能力的几点建议
Debug小技巧: 转载请声明本文的引用出处:仰望大牛的小清新 1.初次编程时,在每一个if后面都写上else,这样,如果你的else原本是不应该运行的,那么就可以在else中输出此时的状态信息便于排 ...
- [Python Debug]Kernel Crash While Running Neural Network with Keras|Jupyter Notebook运行Keras服务器宕机原因及解决方法
最近做Machine Learning作业,要在Jupyter Notebook上用Keras搭建Neural Network.结果连最简单的一层神经网络都运行不了,更奇怪的是我先用iris数据集跑了 ...
- [Python Debug] How to install external python package? MAC系统下的xgboost安装
从昨天晚上开始安装xgboost,经历了各种稀奇古怪的错误,终于现在程序可以跑起来了.整个过程对python编译环境,路径设置,package安装方法有了一定了解,当然还有一些疑惑,所以姑且做个记录. ...
随机推荐
- Storm: 遇到问题总结
1.没有ack : kafkaspout id 重复导致每次读最新没有数据. 2.由于storm提供的读取kafka的enternal工具存在bug,导致重复读取数据,致使数据不准确.storm bu ...
- linux系统下单节点hadoop2的配置
Jdk安装: jdk-7u45-linux-x64.gz cp jdk-7u45-linux-x64.gz /usr/java/ cd /usr/java/ tar -zxvf jdk-7u45-li ...
- OpenCV学习笔记(十) 直方图操作
直方图计算 直方图可以统计的不仅仅是颜色灰度, 它可以统计任何图像特征 (如 梯度, 方向等等).直方图的一些具体细节: dims: 需要统计的特征的数目, 在上例中, dims = 1 因为我们仅仅 ...
- ASP.NET Core 利用中间件支持跨域请求
方法1: 在Startup的ConfigureServices()中添加services.AddCors()在Startup的Configure()中添加app.UseCors(); 保证其在app. ...
- linux/mac下的配置自定义命令alias
linux/mac下的自定义命令alias,并保存别名使其永久生效(重启不会失效) 在做开发每次提交代码的命令都是一长串参数,不想去记,于是可以使用alias命令来解决这个问题:alias aComm ...
- Atom-无懈可击的Markdown编辑器
备战美赛期间,向岳神学习,搞了Atom玩协作开发,第一次没有自动补全的手撸了遗传算法.今天发现Atom还有写Markdown的妙用,遂拿来练手. 1. 安装Atom 下载安装Atom:https:// ...
- Leetcode 560.和为k的子数组
和为k的子数组 给定一个整数数组和一个整数 k,你需要找到该数组中和为 k 的连续的子数组的个数. 示例 1 : 输入:nums = [1,1,1], k = 2 输出: 2 , [1,1] 与 [1 ...
- 微信小程序--列表渲染
HTML: <view class="content" wx:for="{{oneList}}" wx:key = "id" bind ...
- C#从大图中截取一部分图片
#region 从大图中截取一部分图片 /// <summary> /// 从大图中截取一部分图片 /// </summary> /// <param name=&quo ...
- Spring MVC请求到处理方法注解配置的几种方式
@RequestMapping 这个是最常用的注解,可以配置在类上,也可以配置在方法上,两个一起作用组成方法能够响应的请求路径,举例如下 package org.zln.myWeb.controlle ...