Pandas怎样按条件删除行?
To directly answer this question's original title "How to delete rows from a pandas DataFrame based on a conditional expression" (which I understand is not necessarily the OP's problem but could help other users coming across this question) one way to do this is to use the drop method:
df = df.drop(some labels)
df = df.drop(df[<some boolean condition>].index)
Example
To remove all rows where column 'score' is < 50:
df = df.drop(df[df.score < 50].index)
In place version (as pointed out in comments)
df.drop(df[df.score < 50].index, inplace=True)
Multiple conditions
(see Boolean Indexing)
The operators are: | for or, & for and, and ~ for not. These must be grouped by using parentheses.
To remove all rows where column 'score' is < 50 and > 20
df = df.drop(df[(df.score < 50) & (df.score > 20)].index)
Pandas怎样按条件删除行?的更多相关文章
- pandas 获取不符合条件的dataframe
pandas 获取不符合条件的dataframe 或将其过滤掉: df[df["col"].str.contains('this'|'that')==False] >> ...
- pandas dataframe 满足条件的样本提取
pandas 的dataframe 对 数据查询可以通过3种方式 . 预备知识: 1. pandas 的索引和label都是从0开始的计数的 2. 时间切片都是左闭右开的. [5:6,:] 只会输出 ...
- [译]在Pandas的Dataframe中删除行、列
导入模块 import pandas as pd 创建dataframe data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'], 'yea ...
- pandas.Dataframe复杂条件过滤
https://stackoverflow.com/questions/11418192/pandas-complex-filter-on-rows-of-dataframe mask = df.ap ...
- [译]如何根据条件从pandas DataFrame中删除不需要的行?
问题来源:https://stackoverflow.com/questions/13851535/how-to-delete-rows-from-a-pandas-dataframe-based-o ...
- Pandas处理日常EXCEL表格的便捷操作
第一次写博客,写的可能有点乱,有问题可以一起探讨.格式可能控制也不是太好. 1.日常的数据集大多带有中文格式,例如“公务员招聘岗位汇总.xls”.我们使用pandas的read_csv()函数读取可能 ...
- Python | Pandas数据清洗与画图
准备数据 2016年北京PM2.5数据集 数据源说明:美国驻华使馆的空气质量检测数据 数据清洗 1. 导入包 import numpy as np import matplotlib.pyplot a ...
- 电商打折套路分析 —— Python数据分析练习
电商打折套路分析 ——2016天猫双十一美妆数据分析 数据简介 此次分析的数据来自于城市数据团对2016年双11天猫数据的采集和整理,原始数据为.xlsx格式 包括update_time/id/tit ...
- MySQL常用SQL总结
1. 常见命令 连接本地数据库与远程数据库(172.16.xx.xx:3306): mysql -h localhost -u root -p123 mysql -h 172.16.xx.xx -P ...
随机推荐
- iOS开发之SceneKit框架--加载多个模型.dae/.scn文件
1.通过SCNGeometry或子类SCNParametricGeometry创建 相关链接:iOS开发之SceneKit框架--SCNGeometry.h iOS开发之SceneKit框架--SCN ...
- Assert(断言) 的用法
Assert Assert是断言的意思,头文件为assert.h, assert是一个宏 功 能: 测试一个条件并可能使程序终止 用 法: void assert(int test); 在单元测试中经 ...
- ps快速将白底图片变为透明图片
方法一: 如果图层有锁图标,则要点击它,然它消失.然后选中魔棒工具,然后点击图片上要透明的区域,按下backspace键即可. 方法二: 转载自:https://blog.csdn.net/sunyi ...
- MySQL二进制包安装及启动问题排查
环境部署:VMware10.0+CentOS6.9(64位)+MySQL5.7.19(64位)一.操作系统调整 # 更改时区 .先查看时区 [root@localhost ~]# date -R Tu ...
- jquery 表单验证插件
其他: <form action=""> First name: <input type="text" name="FirstNam ...
- JS数组 谁是团里成员(数组赋值)var myarray = new Array(66,80,90,77,59);//创建数组同时赋值
谁是团里成员(数组赋值) 数组创建好,接下来我们为数组赋值.我们把数组看似旅游团的大巴车,大巴车里有很多位置,每个位置都有一个号码,顾客要坐在哪个位置呢? 第一步:组个大巴车 第二步:按票对号入座 大 ...
- go string和[ ]byte
https://www.cnblogs.com/zhangboyu/p/7623712.html
- YXcms前台注入(有限制但可以绕过)
这个cms很久前做过代码审计,很多问题,但是经过这么长时间,现在安全性提高了不少,这几天看了下,基本没有什么特别大的问题了(不包含后台). 在yxcms/protected/apps/member/c ...
- js怎样把URL链接的参数截取出来
有时候,A页面参数需要传递到B页面,则把参数拼接到跳转B页面的url上,这时怎样在另一个页面截取A页面传递的参数呢,主要代码如下 /** * 获取指定的URL参数值 URL:http://www.qu ...
- js微信禁止分享
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js ...