求Excel函数如何将计算一列中重复出现数据的次数重复文本在另计算一列中重复出现数据的次数按照发生频率排序?

如图,在A列单元格区域中,有一些内容。但是部分内容重复了。在Excel里面,有很多方法可以来查找到重复值。今天来介绍一下使用公式,在B列里面列出哪些值是有重复的。在单元格B2照片那个,输入公式:=INDEX($A$1:$A$14,MATCH(0,COUNTIF($B$1:B1,$A$1:$A$14)+IF(COUNTIF($A$1:$A$14,$A$1:$A$14)>1,0,1),0))这里要用到数组公式,输入以后按Ctrl+Shift+Enter来返回结果。然后拖动单元格右下角向下复制公式,如图所示,有重复值的会显示出来,但是当没有重复值以后,结果就显示错误了。下面就来详细分解一下这个公式。1. COUNTIF($B$1:B1,$A$1:$A$14)COUNTIF函数是根据条件来进行计数,在这里条件为$A$1:$A$14的每一个单元格内容,区域是单元格B1。这时单元格B1为空,因此不管条件是什么,计数结果都是0,数组公式的话,结果就是:{0;0;0;0;0;0;0;0;0;0;0;0;0;0}将这部分公式直接输入到单元格中再按Ctrl+Shift+Enter的话返回的结果为0。如果需要查看,选择单元格B2,在编辑栏中选中这部分公式,按F9键,就会显示出来了。2. COUNTIF($A$1:$A$14,$A$1:$A$14)这是第二个COUNTIF函数,条件和区域均为$A$1:$A$14,在这个数组函数中,每一个单元格都会和其他单元格进行查找匹配,如果有重复值的话,COUNTIF计数就会加一。例如A1单元格为苹果,与A2:A14单元格中的值进行匹配,发现了一个匹配上的单元格A12,因此就加上1。这部分公式返回的结果为:{2;2;2;1;1;1;1;1;1;1;1;2;2;2}。也可以使用F9键来进行查看。3. IF(COUNTIF($A$1:$A$14,$A$1:$A$14)>1,0,1)判断COUNTIF函数返回的结果是否大于1,是的话返回0,否则返回1。根据上面一步COUNTIF函数的结果,如果有重复的话,返回的值是2大于1,IF函数就会返回0;否则就返回1。这里判断以后的结果是:{0;0;0;1;1;1;1;1;1;1;1;0;0;0}4. COUNTIF($B$1:B1,$A$1:$A$14)+IF(COUNTIF($A$1:$A$14,$A$1:$A$14)>1,0,1)这里比较简单,直接相加就可以,返回的结果为:{0;0;0;1;1;1;1;1;1;1;1;0;0;0}5.根据前面的步骤简化了以后为:MATCH(0,{0;0;0;1;1;1;1;1;1;1;1;0;0;0},0)查找值0需要在数组{0;0;0;1;1;1;1;1;1;1;1;0;0;0}中进行精确匹配,匹配到第一个精确的值就会返回位置。在这个数组中第一个值就匹配,因此返回第一个值的位置1。6. 根据前面的步骤简化了以后为:=INDEX($A$1:$A$14,1)返回$A$1:$A$14中位置为1的单元格的值,这里就会返回苹果。上述是在单元格B2里面输入以后的返回结果,验证以后是正确的,在$A$1:$A$14中苹果是有重复出现的。下拉复制以后,在单元格B3里面,公式变为:=INDEX($A$1:$A$14,MATCH(0,COUNTIF($B$1:B2,$A$1:$A$14)+IF(COUNTIF($A$1:$A$14,$A$1:$A$14)>1,0,1),0))第一个COUNTIF中变为$B$1:B2,这样可以把查找过的值排除,不会再接在来的MATCH函数中匹配到。一直向下复制的话这部分引用区域会自动更新。因此,当没有重复值,无法匹配的时候,就会返回错误。以上就是在另一列中返回重复值的公式和步骤详解了,可以实际进行尝试一下。想了解更多Excel的操作技巧,欢迎关注微信公众号:tobefascinating,一起学习,一起进步。

选择擅长的领域继续答题?
{@each tagList as item}
${item.tagName}
{@/each}
手机回答更方便,互动更有趣,下载APP
提交成功是否继续回答问题?
手机回答更方便,互动更有趣,下载APP
展开全部1、点击桌面系统中的excel应用程序按钮图标,进入到主界面中2、之后在excel中输入相应的成绩数据信息,设定一个名次列3、之后点击工具菜单栏上的公式按钮4、之后点击菜单下的自动求和函数,然后点击下拉框中的其他函数,这个按钮5、然后在插入函数中,选择rank这个排序函数,需要下拉慢慢寻找6、在rank函数界面中,number这个选项,点中自己要排序的数字,就完成设置,在number,就是要比较的数字范围,这个时候就要输入,数字的范围,具体为D$8:D$17,这个是要输入的,尤其是$,这里不能直接选择下拉的7、之后就可以通过点击第一个排名单元格,然后下拉单元格,完成排名信息的生成',getTip:function(t,e){return t.renderTip(e.getAttribute(t.triangularSign),e.getAttribute("jubao"))},getILeft:function(t,e){return t.left+e.offsetWidth/2-e.tip.offsetWidth/2},getSHtml:function(t,e,n){return t.tpl.replace(/\{\{#href\}\}/g,e).replace(/\{\{#jubao\}\}/g,n)}},baobiao:{triangularSign:"data-baobiao",tpl:'{{#baobiao_text}}',getTip:function(t,e){return t.renderTip(e.getAttribute(t.triangularSign))},getILeft:function(t,e){return t.left-21},getSHtml:function(t,e,n){return t.tpl.replace(/\{\{#baobiao_text\}\}/g,e)}}};function l(t){return this.type=t.type
"defaultTip",this.objTip=u[this.type],this.containerId="c-tips-container",this.advertContainerClass=t.adSelector,this.triangularSign=this.objTip.triangularSign,this.delaySeconds=200,this.adventContainer="",this.triangulars=[],this.motherContainer=a("div"),this.oTipContainer=i(this.containerId),this.tip="",this.tpl=this.objTip.tpl,this.init()}l.prototype={constructor:l,arrInit:function(){for(var t=0;t0}});else{var t=window.document;n.prototype.THROTTLE_TIMEOUT=100,n.prototype.POLL_INTERVAL=null,n.prototype.USE_MUTATION_OBSERVER=!0,n.prototype.observe=function(t){if(!this._observationTargets.some((function(e){return e.element==t}))){if(!t
1!=t.nodeType)throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(),this._checkForIntersections()}},n.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter((function(e){return e.element!=t})),this._observationTargets.length
(this._unmonitorIntersections(),this._unregisterInstance())},n.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorIntersections(),this._unregisterInstance()},n.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},n.prototype._initThresholds=function(t){var e=t
[0];return Array.isArray(e)
(e=[e]),e.sort().filter((function(t,e,n){if("number"!=typeof t
isNaN(t)
t1)throw new Error("threshold must be a number between 0 and 1 inclusively");return t!==n[e-1]}))},n.prototype._parseRootMargin=function(t){var e=(t
"0px").split(/\s+/).map((function(t){var e=/^(-?\d*\.?\d+)(px|%)$/.exec(t);if(!e)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(e[1]),unit:e[2]}}));return e[1]=e[1]
e[0],e[2]=e[2]
e[0],e[3]=e[3]
e[1],e},n.prototype._monitorIntersections=function(){this._monitoringIntersections
(this._monitoringIntersections=!0,this.POLL_INTERVAL?this._monitoringInterval=setInterval(this._checkForIntersections,this.POLL_INTERVAL):(r(window,"resize",this._checkForIntersections,!0),r(t,"scroll",this._checkForIntersections,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in window&&(this._domObserver=new MutationObserver(this._checkForIntersections),this._domObserver.observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))))},n.prototype._unmonitorIntersections=function(){this._monitoringIntersections&&(this._monitoringIntersections=!1,clearInterval(this._monitoringInterval),this._monitoringInterval=null,i(window,"resize",this._checkForIntersections,!0),i(t,"scroll",this._checkForIntersections,!0),this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null))},n.prototype._checkForIntersections=function(){var t=this._rootIsInDom(),n=t?this._getRootRect():{top:0,bottom:0,left:0,right:0,width:0,height:0};this._observationTargets.forEach((function(r){var i=r.element,a=o(i),c=this._rootContainsTarget(i),s=r.entry,u=t&&c&&this._computeTargetAndRootIntersection(i,n),l=r.entry=new e({time:window.performance&&performance.now&&performance.now(),target:i,boundingClientRect:a,rootBounds:n,intersectionRect:u});s?t&&c?this._hasCrossedThreshold(s,l)&&this._queuedEntries.push(l):s&&s.isIntersecting&&this._queuedEntries.push(l):this._queuedEntries.push(l)}),this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)},n.prototype._computeTargetAndRootIntersection=function(e,n){if("none"!=window.getComputedStyle(e).display){for(var r,i,a,s,u,l,f,h,p=o(e),d=c(e),v=!1;!v;){var g=null,m=1==d.nodeType?window.getComputedStyle(d):{};if("none"==m.display)return;if(d==this.root
d==t?(v=!0,g=n):d!=t.body&&d!=t.documentElement&&"visible"!=m.overflow&&(g=o(d)),g&&(r=g,i=p,a=void 0,s=void 0,u=void 0,l=void 0,f=void 0,h=void 0,a=Math.max(r.top,i.top),s=Math.min(r.bottom,i.bottom),u=Math.max(r.left,i.left),l=Math.min(r.right,i.right),h=s-a,!(p=(f=l-u)>=0&&h>=0&&{top:a,bottom:s,left:u,right:l,width:f,height:h})))break;d=c(d)}return p}},n.prototype._getRootRect=function(){var e;if(this.root)e=o(this.root);else{var n=t.documentElement,r=t.body;e={top:0,left:0,right:n.clientWidth
r.clientWidth,width:n.clientWidth
r.clientWidth,bottom:n.clientHeight
r.clientHeight,height:n.clientHeight
r.clientHeight}}return this._expandRectByRootMargin(e)},n.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map((function(e,n){return"px"==e.unit?e.value:e.value*(n%2?t.width:t.height)/100})),n={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return n.width=n.right-n.left,n.height=n.bottom-n.top,n},n.prototype._hasCrossedThreshold=function(t,e){var n=t&&t.isIntersecting?t.intersectionRatio
0:-1,r=e.isIntersecting?e.intersectionRatio
0:-1;if(n!==r)for(var i=0;i0&&function(t,e,n,r){var i=document.getElementsByClassName(t);if(i.length>0)for(var o=0;o推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
为你推荐:
下载百度知道APP,抢鲜体验使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。扫描二维码下载
×个人、企业类侵权投诉
违法有害信息,请在下方选择后提交
类别色情低俗
涉嫌违法犯罪
时政信息不实
垃圾广告
低质灌水
我们会通过消息、邮箱等方式尽快将举报结果通知您。说明
做任务开宝箱累计完成0
个任务
10任务
50任务
100任务
200任务
任务列表加载中...
前言工作中想对 excel 进行一个简单的统计,历时三个小时终于搞定,效果如下:1. 源代码话不多说,直接上源码,可以直接食用,只需将目标文件设置为你需要统计的文件即可。# -*- coding:utf-8 -*-
import xlrd
from collections import Counter
infos = []
# 目标文件
report = '2019.xlsx'
info_file = xlrd.open_workbook(report)
info_sheet = info_file.sheets()[1]
row_count = info_sheet.nrows
for row in range(0, row_count):
# 5 为要统计的列序号,注意从 0 开始
infos.append(info_sheet.cell_value(row, 5))
def all_list(arr):
result = {}
for i in set(arr):
result[i] = arr.count(i)
return result
d = all_list(infos)
d2 = sorted(d.items(), key = lambda x:x[1], reverse = True)
print(d2)
2. 模块解析接下来对每个模块进行解说。2.1 文件打开# 目标文件
report = '2019.xlsx'
info_file = xlrd.open_workbook(report)
info_sheet = info_file.sheets()[1]
第一步自然要打开文件,这里需要引用 xlrd 库。第一行定义目标文件,第二行打开,第三行选择表。注意:表的序号从 0 开始:如图,“Sheet1” 对应的是 info_sheet = info_file.sheets()[0],而 “sheet2” 对应 info_sheet = info_file.sheets()[1]。2.2 数据读取infos = []
for row in range(0, row_count):
infos.append(info_sheet.cell_value(row, 5))
定义一个 list ,用来存储读取的数据。然后以列数为界限,利用 for 循环将每行你需要的列数据进行存储。2.3 频率统计def all_list(arr):
result = {}
for i in set(arr):
result[i] = arr.count(i)
return result
定义一个 dict ,将刚刚得到的 list 进行唯一处理, 然后将每个数据进行统计。这里 dict 的 key - value 分别对应 “ 数据 - 频率 ”。2.4 按频排序d2 = sorted(d.items(), key = lambda x:x[1], reverse = True)
将刚刚得到的 dict 按照 value 值的大小进行倒序排序。正序排序只需将代码改为:d2 = sorted(d.items(), key = lambda x:x[1], reverse = True)。

我要回帖

更多关于 计算一列中重复出现数据的次数 的文章

 

随机推荐