python 找出两个dataframe中不同的元素
pandas从Excel中读取数据,数据格式为dataframe格式
用for循环对进行两个列的数据比较想找出不同的元素时,发现数据是一样的,但是比较结果却是相同和不同的都存在(总之就是不是我以为的效果)
后来将要对比的两列数据先转成list再对比,得出理想结果(反思老感觉很简单的功能写了一大堆),如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-import pandas as pd####test1.xlsx的item列,将会和test.xlsx的Item列数据进行对比
df1 = pd.read_excel('test1.xlsx')
dfItem_Old = df1['item']####test表的Item列
df = pd.read_excel('test.xlsx')
dfItem_New = df['Item']
dfCommand_New = df['Command']
dfValue_New = df['Value']
dfAutotest = df['Autotest']
dfProgress = df['Progress']#####将要对比的两个dataframe格式数据先转为list
dfItem_New = dfItem_New.tolist()
dfItem_Old = dfItem_Old.tolist()####找出在dfItem_New列表中但是不在dfItem_Old列表中的元素
differentKey = [x for x in dfItem_New if x not in dfItem_Old]
#print(differentKey)
####test.xlsx中需要的关键数据保存在字典中
dict_new = {'item':dfItem_New, 'autotest':dfAutotest, 'command':dfCommand_New, 'value':dfValue_New, 'progress':dfProgress}
####将differentKey不同的元素和字典中的item列作对比,如果存在的话就删除,且同时将其他列的此行一并删除(否则会出现行数不一致,报错)
for i in differentKey:if i in dict_new['item']:####找出不同元素的下标,index = dict_new['item'].index(i)#print(index)dict_new['item'].pop(index)dict_new['autotest'].pop(index)dict_new['command'].pop(index)dict_new['value'].pop(index)dict_new['progress'].pop(index)#else:#print(i)
####将删除后的数据重组
Item = dict_new['item']
Autotest = dict_new['autotest']
Command = dict_new['command']
Value = dict_new['value']
Progress = dict_new['progress']
dict = {'Item':Item, 'Autotest':Autotest, 'Command':Command, 'Value':Value, "Progress":Progress}
python 找出两个dataframe中不同的元素相关推荐
- 找出两列表的共有元素python_python 找出两个dataframe中不同的元素
pandas从Excel中读取数据,数据格式为dataframe格式 用for循环对进行两个列的数据比较想找出不同的元素时,发现数据是一样的,但是比较结果却是相同和不同的都存在(总之就是不是我以为的效 ...
- 高效的找出两个List中的不同元素
转自同名博文,未知真正出处,望作者见谅 如题:有List<String> list1和List<String> list2,两个集合各有上万个元素,怎样取出两个集合中不同的元素 ...
- 汇编语言(十五)之找出两个数组中的相同元素
找出两个数组中的相同元素,并且输出 程序运行: 代码: datas segmentA dw -1,-2, 3, 4, 5, 6, 7, 8, 9, 10,-11, 12, 13, 14, 15ACou ...
- js 快速找出两个数组中的不同元素或对象
js 快速找出两个数组中的不同元素 var arr1 = [0,1,2,3,4,5]; var arr2 = [0,4,6,1,3,9]; function getArrDifference(arr1 ...
- JS案例——找出两个数组中的不同元素或对象、数组去重
一.找出两个数组中的不同元素或对象 1. 数据 var arr1 = ["张瑞淑", "徐海涛", "谢岗岗", "薛鹏" ...
- js找出两个数组中不同的元素
function getNewArr(a,b){const arr = [...a,...b];const newArr = arr.filter(item => {return !(a.inc ...
- python找出两个列表不同元素_python 找出两个列表的相同元素与不同元素
python 找出两个列表的相同元素与不同元素,用了以下几种方法 1. 通过set 集合 list1 = [1,2,3] list2=[2,3,4] set1 = set(list1) set2 = ...
- 找出两个字符串中最大子字符串,如abractyeyt,dgdsaeactyey的最大子串为actyet
// 最大子字符串.cpp : 定义控制台应用程序的入口点. // //找出两个字符串中最大子字符串,如"abractyeyt","dgdsaeactyey"的 ...
- 找出两个字符串中最长的相同子字符串
//找出两个字符串中最长的相同子字符串public class Stringdemo {public static void main(String[] args) {String str1 = ne ...
最新文章
- ZBrush关于遮罩的一些操作
- 滚动触发的翻转式文字引用效果
- 边框回归的损失函数_一文搞懂常用的七种损失函数
- 对一次ARP欺骗分析
- 构建持续交付_如何使交付成为您的重点将如何帮助您构建高质量的应用程序
- js更新数组对象_7 种Vue 数据已更新而页面没有更新的情况及深化总结(收藏)
- python模拟登陆遇到重定向_python - scrapy模拟登陆知乎出现重定向无法登陆问题
- 《转》Unsafe与CAS
- 海康威视面试-java应用开发
- 受婴儿抓阄启发,谷歌让机器臂自学抓取物体,不用标注数据
- java AES加密解密
- Cisco交换机下载IOS
- 音高和频率转换(转载)
- Wooboo第四批(暨6月7日)上传程序送百元现金活动获奖公告
- 微信小程序用户信息解
- ionic 环境搭建,运行项目到浏览器,android手机,模拟器
- H5 iOS微信端点击图片触发3Dtouch,导致无法扫描二维码【解决方法】
- 入门必看!ui设计分类有哪些?【萧蕊冰】
- 软件工程毕业设计课题(57)微信小程序毕业设计JAVA投票评选小程序系统设计与实现
- c语言printf输出字符表情,C语言中printf输出的奇怪错误