我有一个dataframe,它有一个ID列和一个相关的数组列,其中包含其相关记录的ID
ID | NAME | RELATED_IDLIST
--------------------------
123 | mike | [345,456]
345 | alen | [789]
456 | sam | [789,999]
789 | marc | [111]
555 | dan | [333]
根据上面的内容,我需要在所有相关的子ID与其父ID之间建立一个关系
ID | NAME | RELATED_IDLIST
--------------------------
123 | mike | [345,456,789,999,111]
345 | alen | [789,111]
456 | sam | [789,999,111]
789 | marc | [111]
555 | dan | [333]
我需要你帮我弄清楚上面的内容
通过使用
Self joins
和Window functions
可以解决这个问题。 我将代码分为5个步骤。算法如下:您可以尝试以下代码:
相关问题 更多 >
编程相关推荐