This is not a duplicate of:
Fastest way to perform complex search on pandas dataframe
Note: pandas ver 0.23.4
Assumptions: data can be laid out in any order.
I have a list:
L = ['A', 'B', 'C', 'D', 'L', 'M', 'N', 'O']
I also have a dataframe. Col1 and Col2 have several associated columns that have related info I wish to keep. The information is arbitrary so I have not filled it in.
Col1 Col2 Col1Info Col2Info Col1moreInfo Col2moreInfo
A B x x x x
B C
D C
L M
M N
N O
I am trying to perform a 'search and group' for each element of the list. For example, if we performed a search on an element of the list, 'D', the following group would be returned.
To From Col1Info Col2Info Col1moreInfo Col2moreInfo
A B x x x x
B C
D C
I have been playing around with networkx but it is a very complex package.