我使用的是来自CPC website的批量数据(CPC有效符号列表)。我已经将csv读入一个文件,前30行(超过260K)是:
SYMBOL level not-allocatable additional-only
1 A 2 True False
2 A01 4 True False
3 A01B 5 True False
4 A01B 1/00 7 False False
5 A01B 1/02 8 False False
6 A01B 1/022 9 False False
7 A01B 1/024 9 False False
8 A01B 1/026 9 False False
9 A01B 1/028 9 False False
10 A01B 1/04 9 False False
11 A01B 1/06 8 False False
12 A01B 1/065 9 False False
13 A01B 1/08 9 False False
14 A01B 1/10 9 False False
15 A01B 1/12 9 False False
16 A01B 1/14 9 False False
17 A01B 1/16 8 False False
18 A01B 1/165 9 False False
19 A01B 1/18 9 False False
20 A01B 1/20 8 False False
21 A01B 1/22 8 False False
22 A01B 1/222 9 False False
23 A01B 1/225 10 False False
24 A01B 1/227 9 False False
25 A01B 1/24 8 False False
26 A01B 1/243 9 False False
27 A01B 1/246 9 False False
28 A01B 3/00 7 False False
29 A01B 3/02 8 False False
level值创建层次结构。因此,节点A01B 1/00是级别7,是A01B的子节点。A01B 1/02是级别8,A01B 1/00和A01B 3/00的子节点是A01B的子节点
我想要的是创建一个名为PARENT
的新列,其中包含节点的直接父节点的SYMBOL
。例如,我在Excel中编辑了csv以显示前几行的所需结果:
Note: there are no level 1, 3, or 6 symbols. There are multiple level 2 symbols. There is no parent for level 2 symbols, the parent of level 4 symbols can be assigned the first level 2 symbol above it, and the parent of level 7 symbols likewise can be assigned the first level 5 symbol above it.
编辑:我需要更好地解释如何确定节点的父节点。级别值和行位置是确定父级所需的全部。
我想用熊猫来做这项工作,但我不知道如何开始。有人要吗?谢谢
在这个答案中,我假设你的直接父母总是排在你自己的上面,因为这是你期望的结果和你的图表所暗示的。你知道吗
根据这个假设,我们可以为每一行取最接近的一行,其级别低于该行:
输出:
这是另一种方法。GetParent()返回一个函数,该函数跟踪每个级别的最新符号,并返回当前级别的父级。把它用在熊猫。应用()使用父符号创建列。你知道吗
输出:
相关问题 更多 >
编程相关推荐