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中如何在两个工作表中查找重复数据
有时我们可能会在两种工作表中查找重复记录,当数据记录很多时,就必须通过简单的方法来实现.下面小编就与大家一起分享一下查看重复记录数据的方法,希望对大家有所帮助. 方法/步骤 为了讲解的需要,小编特 ...
随机推荐
- NOIP2018D1T1 铺设道路
原题:NOIP2013D1T1 积木大赛 题目地址:P5019 铺设道路 思路:玄学瞎搞 将每块区域插入一个小根堆,这里的小根堆用优先队列实现,即运用一个 \(pair\) , \(first\) 为 ...
- 【转】Python 3的pathlib模块:驯服文件系统
[转]Python 3的pathlib模块:驯服文件系统 https://python.freelycode.com/contribution/detail/1248 Python部落(python. ...
- 使用 ffmpeg nginx rtmp 搭建实时流处理平台
环境: ubuntu 16.04 问题引入: 使用 opencv 获取摄像头数据帧, 进行处理之后(如进行 keypoint 识别), 将 opencv 中图像的 Mat类型转化为 ffmpeg 的 ...
- MySQL查看表的索引【转】
查看表的索引: show index from table_name(表名) 结果列表中各字段的含义: · Non_unique 如果索引不能包括重复词,则为0.如果可以,则为1. · Key_nam ...
- linux shell 之尝试编写 企业级 启动脚本
企业Shell面试题10:开发企业级MySQL启动脚本 说明: MySQL启动命令为: 1 /bin/sh mysqld_safe --pid-file=$mysqld_pid_file_path 2 ...
- 解决flask中文乱码的问题
from flask import Flask,jsonify app = Flask(__name__) #使用jsonify模块来让网页直接显示json数据 @app.route('/json') ...
- 自学MVC看这里——全网最全ASP.NET MVC 教程汇总(转)
自学MVC看这里——全网最全ASP.NET MVC 教程汇总 MVC架构已深得人心,微软也不甘落后,推出了Asp.net MVC.小编特意整理博客园乃至整个网络最具价值的MVC技术原创文章,为想要 ...
- 深入学习NAT工作原理
深入学习NAT工作原理 我们单位中的电脑很多,组成了一个局域网,网络中只有一个电脑和外网(Internet)相连,当然有一个外网地址,但仅仅一个.我以前一直不明白,我们局域网的电脑均能上网,几台同时上 ...
- ubuntu 16.04 登录后黑屏
进入登录界面后黑屏,重新更新英伟达的显卡,也么有起作用. 解决办法,进入登录界面时,进入终端(ctrl+alt+f1),然后修改 grub配置文件,使其每次重启时都检查文件 sudo vi /etc ...
- hostapd修改beacon帧和probe response帧
在AP模式下,热点会不断定期地发送Beacon帧来宣告自己存在,告知设备可以加入网络: Probe Response帧是用于应答Probe Request帧,Probe Request帧是移动工作站用 ...