[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安装方法有了一定了解,当然还有一些疑惑,所以姑且做个记录. ...
随机推荐
- PAT Basic 1085
1085 PAT单位排行 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤105),即考生人数.随后 N 行, ...
- [网站公告]又拍云API故障造成图片无法上传(已恢复)
大家好,18:00左右开始,又拍云API出现故障,调用图片上传API时出现错误:“The remote server returned an error: (403) Forbidden.”,造成图片 ...
- C#入门篇6-1:字符串操作 char常用的函数
//char 字符的常见操作 public static void FChar() { //判定字符的类别 char ch1 = 'a';//使用小引号 bool bl = true; bl = ch ...
- CentOS7 haproxy+keepalived实现高可用集群搭建
一.搭建环境 CentOS7 64位 Keepalived 1.3.5 Haproxy 1.5.18 后端负载主机:192.168.166.21 192.168.166.22 两台节点上安装rabbi ...
- centos7下使用git
问:为什么需要版本控制系统?[转:http://www.cnblogs.com/shenliang123/p/3824383.html] 版本控制是一种记录若干文件内容变化,以便将来查阅特定版本修订情 ...
- HTML5与HTML4的比较
HHTML5封装一些标签和属性,方便了开发. <form> <p> <label>Username:<input name="search" ...
- java _tomcat_mysql 部署
项目做完了,要发布了,而Java的特长之一就是移植性好,面对着微软的XP的停止服务,Windows系统的“独裁”,越来越多的商家选择了开源的免费的linux系统作为服务器.因为linux系统也有图形界 ...
- bzoj 合集 1079 1791 1876 2208 2306
1079 记忆化瞎搞吧,[a][b][c][d][e][l]表示当前有能涂1次的油漆a个,能涂2次的b个….前一个颜色为l,再搞下转移就行了. 1791 基环树上找直径 1876 高精度 2208 看 ...
- windows 批处理删除指定目录下 指定类型 指定天数之前文件
删除D:\test下5天前所有文件,如下: @echo offset SrcDir=D:\testset DaysAgo=5forfiles /p %SrcDir% /s /m *.* /d -%Da ...
- MFC设置对话框背景和边框颜色
对于对话框,只需要重载默认的消息处理函数就行了: // 重载默认的消息处理函数,主要处理WM_MOVE WM_PAINT WM_NCPAINT WM_NCACTIVATE WM_NOTIFY这// 几 ...