python DataFrame 取差集
来源:互联网 发布:钢结构荷载计算软件 编辑:程序博客网 时间:2024/06/12 00:35
需求:给定一个dataframe和一个list,list中存放的是dataframe中某一列的元素,删除dataframe中与list元素重复的行(即取差集)。
在网上搜了一圈,好像没看到DataFrame中取差集的方式,所以自己写了一个。方法比较繁琐,如果有更简便的方式,请留言。
import pandas as pddata = [[1,2,3],[2,3,4],[3,4,5],[4,5,6]]# 创建dataframe,包含a,b,c三列df = pd.DataFrame(data, columns=['a','b','c'])print(df)# a 列中待删除的元素a_to_drop = [1, 3]# 找到待删除元素所在的位置,返回的是 true or false 序列flag = df['a'].isin(a_to_drop)# 由于我们要取差集,因此对上述序列取反diff_flag = [not f for f in flag]# res 为我们所需要的差集res = df[diff_flag]# 重置indexres.index = [i for i in range(len(res))]print(res)
阅读全文
0 0
- python DataFrame 取差集
- Python dataframe to array
- python中dataframe合并
- python dataframe基础入门
- python dataframe unionall
- python dataframe where
- python dataframe join
- python dataframe groupby
- python dataframe rename
- python dataframe NaN处理
- python dataframe的索引
- python中Dataframe学习
- Python DataFrame 添加行
- Python合并DataFrame
- Python dataframe.pivot()
- Python:dataframe转html
- python dict to dataframe
- python学习记录-Dataframe
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- react native学习笔记18——存储篇(3)Realm
- xtrabackup恢复备份后,mysql无法启动,报Job failed to start
- lightdm-login-chromeos, 将 chromiumos vibe窗口管理器安装到 Ubuntu
- at91sam9260的Telnet远程登录开发板
- python DataFrame 取差集
- Spring Security 默认的过滤器链
- eclipse上tomcat运行动态网页404的解决方法(并不完美但有效)
- CocosCreator PageView组件使用
- js:继承
- 正则表达式对象中lastIndex属性
- 数据结构实验之图论六:村村通公路
- web开发会话跟踪技术
- 数据结构中的各种树