excel 中怎么让两列姓名相同排序(转)
如图,A列B列不动,C列和D列行值不变,以A列姓名为主让C列姓名和A列相同姓名的对齐(行),D行跟着C行不变。

在E1输入公式=MATCH(C1,A:A,0)然后下拉,接著选中C,D,E列,以E列为标准升序排列即可
转自:https://wenku.baidu.com/view/b7f6198058fb770bf68a5559.html
pandas实现方法:
#! /usr/bin/env python
#-*- coding:utf8 -*-
import pandas as pd
from pandas import DataFrame
import numpy as np
pd.set_option('display.height',10000)
pd.set_option('display.max_rows',5000)
pd.set_option('display.max_columns',5000)
pd.set_option('display.width',10000)
df = pd.read_excel(r"F:\test.xlsx")
col_n = ['C','D']
col_A = ['A','B']
CD = pd.DataFrame(df,columns = col_n)
AB = pd.DataFrame(df,columns = col_A)
# print(CD)
# print(AB)
fi =pd.merge(AB,CD,left_on='A',right_on='C',how='left')
print(fi) zn=fi[fi.isnull().values==True]
print(zn.fillna(0))
改进版
#! /usr/bin/env python
#-*- coding:utf8 -*-
import pandas as pd
from locale import *
from pandas import DataFrame
import numpy as np
writer = pd.ExcelWriter('output.xlsx')
pd.set_option('display.height',10000)
pd.set_option('display.max_rows',5000)
pd.set_option('display.max_columns',5000)
pd.set_option('display.width',10000)
df = pd.read_excel(r"F:\test.xlsx", thousands=',')
print(df.info())
# df = pd.read_excel(r"F:\test.xlsx")
col_A = ['A','B']
col_n = ['C','D']
print(df)
AB = pd.DataFrame(df,columns = col_A)
CD = pd.DataFrame(df,columns = col_n) fi =pd.merge(AB,CD,left_on='A',right_on='C',how='left') # fi['E']=fi.apply(lambda x: (x['D'] - x['B'])/x['D']*100, axis=1).round(2) # fi['E']=fi.apply(lambda x: format((x['D'] - x['B'])/x['D'],'.2%'), axis=1) # fi['E']=(fi.D-fi.B)
# fi['F']=((fi.D-fi.B)/fi.D*100)
fi=fi.assign(E=fi.B-fi.D,F=((fi.B-fi.D)/fi.B)*100).round(2)
# fi=fi.assign(E=fi.B-fi.D,F=((fi.B-fi.D)/fi.B)) def number_to_flag(number):
if number > 0:
return '↑'
elif number == 0:
return '='
else:
return '↓' fi =fi.sort_values(by=['F'],ascending=False) #升序 fi['G'] =fi['F'].map(number_to_flag) fi['E'] = fi['E'].astype('str').str.replace("-","")
fi['F'] = fi['F'].astype('str').str.replace("-","")
fi['F'] = fi.F + '%'
fi=fi.dropna(axis=0)
fi=fi[ ~ fi['F'].str.contains('0.0') ]
fi['E'] = fi['E'].astype('float64')
print(fi)
print(fi.dtypes)
fi.to_excel(writer)
writer.save()
最终版
#! /usr/bin/env python
#-*- coding:utf8 -*-
import sys
reload(sys)
sys.setdefaultencoding('gbk')
from locale import *
from pandas import DataFrame
import pandas as pd
import numpy as np
writer = pd.ExcelWriter('output.xlsx')
pd.set_option('display.height',10000)
pd.set_option('display.max_rows',5000)
pd.set_option('display.max_columns',5000)
pd.set_option('display.width',10000)
df = pd.read_excel(r"F:\test.xlsx")
pd.options.display.float_format = '{:,}'.format print(df.info())
# df = pd.read_excel(r"F:\test.xlsx")
col_A = ['A','B']
col_n = ['C','D'] AB = pd.DataFrame(df,columns = col_A)
CD = pd.DataFrame(df,columns = col_n) fi =pd.merge(AB,CD,left_on='A',right_on='C',how='left') # fi['E']=fi.apply(lambda x: (x['D'] - x['B'])/x['D']*100, axis=1).round(2) # fi['E']=fi.apply(lambda x: format((x['D'] - x['B'])/x['D'],'.2%'), axis=1) # fi['E']=(fi.D-fi.B)
# fi['F']=((fi.D-fi.B)/fi.D*100)
fi=fi.assign(E=fi.B-fi.D,F=((fi.B-fi.D)/fi.B)*100).round(2)
# fi=fi.assign(E=fi.B-fi.D,F=((fi.B-fi.D)/fi.B)) def number_to_flag(number):
if number > 0:
return '↓'
elif number == 0:
return '='
else:
return '↑' fi =fi.sort_values(by=['F'],ascending=False) #升序 fi['G'] =fi['F'].map(number_to_flag) fi['E'] = fi['E'].astype('str').str.replace("-","")
fi['F'] = fi['F'].astype('str').str.replace("-","")
fi['F'] = fi.F + '%'
fi=fi.dropna(axis=0) fi=fi[ ~ fi['F'].str.contains('0.0') ]
fi['E'] = fi['E'].astype('float64')
fi['B'] = fi['B'].astype('float64') print(fi)
# print(fi.dtypes)
fi.to_excel(writer)
writer.save()
# fi.to_html('files.html',escape=False,index=False,sparsify=True,border=1,index_names=False,header=True)
excel 中怎么让两列姓名相同排序(转)的更多相关文章
- excel 快速比对两列数据差异
excel 快速比对两列数据差异 CreateTime--2018年5月31日11:19:35 Author:Marydon 1.情景展示 找出两列数据的差异 2.具体操作 方式一:使用条件格式 ...
- 在EXCEL中如何让一列数字变成文本格式?就是想让单元格的左上角变一个绿绿的?
如何在EXCEL中如何让一列数字变成文本格式?就是想让单元格的左上角变一个绿绿的? 解决方案:将整列单元格格式设为文本,然后,选中该列,数据--分列--完成 详细步骤: (1)选中1行或者1列,再单击 ...
- excel中快捷计算单一列中的所有的值
excel中快捷计算单一列中的所有的值 比如B列中所有的值 =SUM(B1:B100) 计算B列第一行到第100行的值 又学了一招 如果想统计B列所有的值 可以用 =SUM(B:B)
- excel中在某一列上的所有单元格的前后增加
excel中在某一列上的所有单元格的前后增加数字汉字字符等东西的函数这样写 “东西”&哪一列&“东西” 例如 “1111”&E1&“3333”
- 使用Eclipse在Excel中找出两张表中相同证件号而姓名或工号却出现不同的的项
1:首先把Excel中的文本复制到txt中,复制如下: A表: 证件号 工号 姓名 310110xxxx220130004 101 傅家宜3101 ...
- freeMarker中list的两列展示
前台界面中我使用freeMarker的机会有很多,自然也就会接触下<List>标签,我想大家应该都不陌生.<#list attrList as attr>${a.name}&l ...
- EXCELL中怎么将两列数据对比,找出相同的和不同的数据?
假设你要从B列中找出A列里没有的数据,那你就在C1单元格里输入“=IF(ISNA(VLOOKUP(B1,A:A,1,0)),"F","T")”显示T就表示有,F ...
- Excel两行交换及两列交换,快速互换相邻表格数据的方法
经常使用办公软件的人可能有遇到过需要将Excel相邻两行数据相互交换的情况,需要怎么弄才最方便呢?您还是像大家通常所做的那样先在Excel文件相应位置插入一个新的空白行然后在复制粘贴数据然后删除原来那 ...
- Excel中如何在两个工作表中查找重复数据
有时我们可能会在两种工作表中查找重复记录,当数据记录很多时,就必须通过简单的方法来实现.下面小编就与大家一起分享一下查看重复记录数据的方法,希望对大家有所帮助. 方法/步骤 为了讲解的需要,小编特 ...
随机推荐
- Shell-find . -type f -name "*.php" -print0 | xargs -0 wc -l
统计一个源代码目录中所有 php 文件的行数
- MySQL中interactive_timeout和wait_timeout的区别【转】
在用mysql客户端对数据库进行操作时,打开终端窗口,如果一段时间没有操作,再次操作时,常常会报如下错误: ERROR 2013 (HY000): Lost connection to MySQL s ...
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data错误的解决
记录个报错: 问题描述: 经过服务器生成图片返到前台时,在火狐浏览器中下载图片或打开图片时报错:SyntaxError: JSON.parse: unexpected character at lin ...
- Ubuntu18系统qt生成程序无法双击运行问题
1.Ubuntu18 安装qt编译生成的程序文件类型为application/x-sharedlib,无法双击直接运行.文件类型应该为x-executable. 2.解决方法 在.pro文件中添加下面 ...
- FreeSWITCH voicemail
功能描述:分机不存在时,进行语音留言. 步骤: 1.编译mod_voicemail 模块.默认是已经有编译 2.加载mod_voicemail模块: fs_cli --> reload mo ...
- 响应式页面-@media介绍
01 响应式页面-@media介绍, 我们为什么要写自适应的页面(响应式页面) 众所周知,电脑.平板.手机的屏幕是差距很大的,假如在电脑上写好了一个页面,在电脑上看起来不错,但是如果放到手机上的话 ...
- 前端 ----jQuery的属性操作
04-jQuery的属性操作 jquery的属性操作模块分为四个部分:html属性操作,dom属性操作,类样式操作和值操作 html属性操作:是对html文档中的属性进行读取,设置和移除操作.比如 ...
- iptables防护CC和DDos和PPTP穿透脚本
一.iptables优化脚本案例 #!/bin/bash #脚本下载地址:#wget www.mrliangqi.com/pack/shell/iptables.sh #脚本使用:#bash ipta ...
- matplotlib报错_tkinter.TclError: no display name and no $DISPLAY environment variable
import matplotlib import matplotlib.pyplot as plt fig=plt.figure() #交互式测试,此时报错 解决办法,在引用后添加下面这一行 matp ...
- swift 学习- 17 -- 析构器
// 析构器 只适用与 类类型, 当一个类的实例被释放之前, 析构器会被立即调用, 析构器用关键字 deinit 来标示, 类似于构造器要用 init 来标示 // 析构过程原理 // Swift 会 ...