我有一个Pandas数据框,其中每一行表示血统中两个独特点(源和目标)之间的链接。世系可能只会分裂成两个,但它们永远不会合并:
SOURCE_ID TARGET_ID Splitting_event
0 1 68 False
1 68 72 False
2 72 75 False
3 75 81 True
4 75 78 True
5 78 557 False
6 81 85 False
7 85 88 True
8 85 91 True
9 88 298 False
10 91 99 False
11 99 106 False
12 106 112 True
13 106 109 True
我想以一种允许我跟踪每个血统的历史的方式连接分裂事件的源id
例如,查看第13行,附加列“沿袭”的理想值如下所示:
SOURCE_ID TARGET_ID Splitting_event Lineage
13 106 109 True "75.85.106"
到目前为止,我对嵌套for循环和条件的所有尝试都失败了,我不知道如何使用中间链接(spliting\u event=False的链接)连接所有内容。我真的很感激你的帮助
非常感谢
我们需要使用df.apply的熊猫功能
如果这是你想要的,请告诉我
相关问题 更多 >
编程相关推荐