[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安装方法有了一定了解,当然还有一些疑惑,所以姑且做个记录. ...
随机推荐
- Poj3061Subsequence
A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, a ...
- Java中BigInteger类型
BigInteger是java.math包提供的处理大整数类型,实现了大整数的存储,四则运算,判断素数的方法,求幂,求模,求逆元,求最大公约数等方法.本文主要分析下BigInteger对于大整数的存储 ...
- 【Partition List】cpp
题目: Given a linked list and a value x, partition it such that all nodes less than x come before node ...
- IOS开发学习笔记009-OC基本知识
开始学习OC,时间不等人啊,要抓紧了. OC基本知识 新建一个以.m结尾的文件,这既是oc的程序文件.在oc程序中完全兼容C语言.编译好链接类似. oc包含头文件是使用#import <> ...
- Windows网络编程笔记1
第一部分 传统网络API 传统的网络接口NetBIOS.重定向器.邮槽.命名管道等.第一,NetBIOS(Network Basic Input/Output System, NetBIOS)“网络基 ...
- Monkeyrunner 录制脚本&回放
本文主要解释如何使用monkeyrunner来实现脚本的录制和回放 一:准备条件 在电脑端配置 Android SDK环境 java 环境 下载好 SDK后添加环境变量 E:\android- ...
- python学习-- settings 设置sqlserver连接
PyCharm 开发工具 先打开项目 1. ctrl+alt+s 2. project:项目名称 选中Project Interpreter,点右面+号 :搜索 django-pyodbc-az ...
- CSU-2220 Godsend
题目链接 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2220 题目 Description Leha somehow found ...
- hnust CZJ-Superman
问题 B: CZJ-Superman 时间限制: 1 Sec 内存限制: 128 MB提交: 636 解决: 87[提交][状态][讨论版] 题目描述 “那是只鸟?那是飞机?那是——超人!” 程序 ...
- 【LeetCode】Merge Sorted Array(合并两个有序数组)
这道题是LeetCode里的第88道题. 题目描述: 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nu ...