0

A single row in the dataframe looks like the following:

source                                                                           Bubble Sort
target                                        Sorting Algorithms Visualization : Bubble Sort
edge      https://www.geeksforgeeks.org/sorting-algorithms-visualization-bubble-sort/?ref=rp

The columns are source, target and edge. Given two nodes src and dest. I need to perform BFS and get all the edges in the path. For example from source Bubble Sort to target Sorting Algorithms Visualization : Bubble Sort. It should output :

https://www.geeksforgeeks.org/sorting-algorithms-visualization-bubble-sort/?ref=rp.

I am new to python and python dataframes and need a little help figuring this out.

Neha Jain
  • 3
  • 1

1 Answers1

0

I think you're looking for this, if I understood the question correctly:

print(df[(df['source'] == 'Bubble Sort') & (df['target'] == 'Sorting Algorithms Visualization : Bubble Sort')]['edge'])

0    https://www.geeksforgeeks.org/sorting-algorith...
NYC Coder
  • 7,424
  • 2
  • 11
  • 24
  • Does it give the weight if there is an edge between source or target, or it can give a list of edges when a path exists between two nodes? – Neha Jain Apr 25 '20 at 14:42
  • If the dataframe has those 3 columns you mentioned, the above query will give all the edges that satisfy the condition - source = 'Bubble Sort' and target = 'Sorting Algorithms Visualization : Bubble Sort' – NYC Coder Apr 25 '20 at 14:46
  • If a row is ['a','b','1'] and another is ['b','c',2]. If i need a pth between 'a' to 'c'. It should print 1,2 – Neha Jain Apr 25 '20 at 14:50
  • So you're saying b is a target in the first but source in the second row? – NYC Coder Apr 25 '20 at 14:54
  • Yes, and I require path. – Neha Jain Apr 25 '20 at 14:56