type
status
date
slug
summary
tags
category
icon
password
是否阅读
是否阅读
Origin
URL
前面文章简单介绍了 PQ 常用的菜单操作,这篇文章我将通过菜单操作解题的方式来把前面所学的技巧过一遍。
题目:
下图是 Python 中的著名禅经:The Zen of Python
notion image
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea – let’s do more of those!
这张图是 ASCII 码表的部分内容:
notion image
要求将禅经的内容按字符逐一替换成对应的 ASCII 值然后合并为一个长字符串,同时字符串可以被还原成原文;
问题拆解:
这个问题最核心要解决的问题是 “逐一替换”,在 Excel 中一般是通过 vlookup 函数来解决,在 PQ 中是通过“合并查询” 来实现的,但是合并查询单个字符前我们还需要做很多准备工作,将多行文字变成单列的字符串,结合前面讲过的菜单操作,我们不难想到 “转置——合并列——拆分列——转置——合并查询——转置——合并列” 的基本处理思路。
为了讲述的方便,我把原文简化成三行无意义的字符串来进行演示。
先看看效果:
notion image
· 整理原文:
在转置前,需要注意转置后再拆分列并不是无损操作!这个过程丢失了一个重要的信息——段落!因此我们要找一个合适的字符作为段落标记(类似于转义字符 ),大概扫了一眼全文,“|” 没有出现过,可以试着用竖线标记一下段落(通过添加列操作即可),以便于后面的还原操作能够无损还原文章内容:
notion image
记住每次处理完后,及时地删除不需要的列——“删除其它列”;
notion image
接下来我们对添加了段落标识符的列做转置操作:
notion image
由于拆分列只能对单列进行,因此我们要先合并列
notion image
同样要记得删除其它列,然后按照字符数 1 做拆分列
notion image
这时已经得到了分散的字符了,我们需要做的就是转换成列:
notion image
其实到这里已经可以做合并查询了,但是,PQ 的合并查询类似于快排算法,不保证结果的排列顺序还是原来的样子,因此需要提前加索引
notion image
加了索引后就可以开始用合并查询匹配了(选左外就可以了):
notion image
展开后你会发现,默认的排序打乱了原文,这时候索引的好处就体现了:
notion image
notion image
最后仅保留 ASCII 码转置后合并就得到了题目的答案:
notion image
· 还原文章:
还原操作的要点就是拆分列时分隔字符数为 2:
notion image
剩下的操作逆着来就可以了,需要注意的是索引添加的地方和合并查询时选择的列相比整理的操作是有变化的:
notion image
notion image
还原段落需要注意,合并后要从 “|” 这里拆分列:
notion image
舍弃最后一个多余添加的 “|”:
notion image
至此,文章的转码和还原就讲解到这里了。大家有好玩的,有趣的题可以在公众号里面发私信给我,后面的习题讲解我会抽出来讲解的。
The Zen of Python 转码后的文档下载(提取码:wj92):
https://pan.baidu.com/s/1IjTT-sM6ePMh2aD1tzEdjg
相关文章
PQ 教程_字段梳理 & 数据追加
Lazy loaded image
使用 Power Query 自定义生成日期表
Lazy loaded image
Dim_Data,你值得制作的第一张维度表
Lazy loaded image
数据汇总再不愁!傻瓜式数据汇总工具教学
Lazy loaded image
PQ 教程_文本处理的简单应用
Lazy loaded image
Power Query — 基础知识
Lazy loaded image
Power Query — 基础知识Power Query — Hello World!
Loading...
木木
木木
木木不吃糖
最新发布
OneClickVirt | 一键虚拟化项目
2025-11-6
3 分钟搞定热点新闻 + 文案创作,飞书多维表格 + Coze,小白也能秒上手_飞书多维表格 热点采集 - CSDN 博客
2025-4-18
记一次使用大模型处理大量数据的过程
2025-4-14
VBA 实践 + 把大纲级别分明的 word 文档转换成横向从属结构 excel 表格
2025-1-8
用了这么多年的 Excel,你会筛选的反选功能吗?
2025-1-8
Power Query — 菜单操作(1)
2025-1-8
公告
🎉-- 感谢您的支持 ---🎉