我已經根據ID列表創建了以下大熊貓DataFrame
。切片基於另一個大熊貓數據框
In [8]: df = pd.DataFrame({'groups' : [1,2,3,4],
'id' : ["[1,3]","[2]","[5]","[4,6,7]"]})
Out[9]:
groups id
0 1 [1,3]
1 2 [2]
2 3 [5]
3 4 [4,6,7]
還有另一個DataFrame
如下。
In [12]: df2 = pd.DataFrame({'id' : [1,2,3,4,5,6,7],
'path' : ["p1,p2,p3,p4","p1,p2,p1","p1,p5,p5,p7","p1,p2,p3,p3","p1,p2","p1","p2,p3,p4"]})
我需要獲取每個組的路徑值。 E.g
groups path
1 p1,p2,p3,p4
p1,p5,p5,p7
2 p1,p2,p1
3 p1,p2
4 p1,p2,p3,p3
p1
p2,p3,p4