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 SettingWithCopyWarning was 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 df

The warning offers a suggestion to rewrite as follows:

df.loc[df['A'] > 2, 'B'] = new_val

Or 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_copy flag to False, which will effectively turn off the check, for that object:

tmp.is_copy = False

Or 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.的更多相关文章

  1. 问题解决:SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

    转载:y小川 SettingWithCopyWarning 解决方案 问题场景:我在读取csv文件之后,因为要新增一个特征列并根据已有特征修改新增列的值,结果在修改的时候就碰到了SettingWith ...

  2. [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文件后,在新增一个特征列并根据已有特征修改 ...

  3. 极简Python DeBug工具——PySnooper

    DeBug Python 代码的方式有很多种?比如: (1)设置断点 (2)print函数 (3)... 本文要介绍的是一个新开源的项目PySnooper ,只要给有疑问的代码加上装饰器,各种信息一目 ...

  4. Python Debug工具

    最近在github上冒出了一个python的debug神器PySnooper,号称在debug时可以消灭print.那么该工具有哪些优点呢,如何使用该工具呢.本文就介绍该工具的优缺点和使用方式. 前言 ...

  5. python Debug 单步调试

    一直犯愁的是python的调试,曾经写c都是编译完了用gdb直接调试了,轻松愉快.如今遇到这么一个解释型的程序.不知道怎么办了.用log吧,有时就是一个小程序,不想写这么多代码.打屏吧.有时屏幕翻得快 ...

  6. python debug open_files

    主要是遇到 Error 24, too many open files. 下面这种方法可以debug打开了哪些文件. import __builtin__ openfiles = set() oldf ...

  7. python debug小技巧&&工程能力的几点建议

    Debug小技巧: 转载请声明本文的引用出处:仰望大牛的小清新 1.初次编程时,在每一个if后面都写上else,这样,如果你的else原本是不应该运行的,那么就可以在else中输出此时的状态信息便于排 ...

  8. [Python Debug]Kernel Crash While Running Neural Network with Keras|Jupyter Notebook运行Keras服务器宕机原因及解决方法

    最近做Machine Learning作业,要在Jupyter Notebook上用Keras搭建Neural Network.结果连最简单的一层神经网络都运行不了,更奇怪的是我先用iris数据集跑了 ...

  9. [Python Debug] How to install external python package? MAC系统下的xgboost安装

    从昨天晚上开始安装xgboost,经历了各种稀奇古怪的错误,终于现在程序可以跑起来了.整个过程对python编译环境,路径设置,package安装方法有了一定了解,当然还有一些疑惑,所以姑且做个记录. ...

随机推荐

  1. LCS及方案数(DP)

    Description 对于一个序列

  2. 【Todo】 cygwin下emacs中M-x shell 中出现乱码

  3. kettle - Linux下定时执行kettle作业

    Linux下实现kettle 自动同步数据 1.安装jdk tar -zxvf jdk-7u25-linux-x64.tar.gz -C /usr/share 2.配置java环境 vim /etc/ ...

  4. phpstorm将本地代码传递到远程服务器

    由于对vim不太熟悉,效率比较低,作为过渡阶段,采用本地编写代码,然后上传到开发机上,进行调试 前提是服务器开启了ftp服务:http://www.cnblogs.com/redirect/p/693 ...

  5. 12个scp传输文件的命令栗子

    12个scp传输文件的命令栗子 一直在用scp进行简单的远程复制文件的功能,今天无意间看到一篇介绍scp的文章,便想着学习学习并将其翻译了过来.原文戳这里.翻译不对的地方,敬请指正. 另外我最近搭建了 ...

  6. CSU-1985 驱R符

    CSU-1985 驱R符 Description 阴阳师中有三中稀有度的式神R,SR,SSR,其中R的稀有度最低,每次抽符,会随机得到一种式神,然而子浩君对R式神已经深恶痛绝. 某天,子浩君突然发现, ...

  7. Java 语言概述与开发环境(2)

    目录: 一.JDK配置容易出现的问题 二.HelloWorld程序编译常见问题 三.文档注释 四.Java 标识符 五.转义符 六.运算符之算术运算符   ********************** ...

  8. Linux内存使用消耗高

    Linux系统下如果内存占用很高又找不到是被什么程序占用的,需要考虑下是否是SLAB的问题.SLAB是Linux操作系统的一种内存分配机制,可以使用下面命令来查看.例如: cat /proc/memi ...

  9. POJ 3648 Wedding(2-SAT的模型运用+DFS | Tarjan)

    Wedding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10427   Accepted: 3170   Specia ...

  10. 嵌入式wifi iwconfig编译

    转载自:http://blog.sina.com.cn/s/blog_546ced060101cmru.html     移植wifi无线网卡到mini2440上全过程 前段时间移植了U-boot和l ...