title: Find all parents for a child with lookthru path and other columns in python
body: <p>I am really a newbie in python. Could you please help in the following problem</p>
  
  <p>I have the following table:</p>
  
  <pre><code>Parent  Child   value 1 Value 2
  
  a0      b1      0.2         5
  
  b5      c1      0.3         2
  
  a0      b2      0.5         6
  
  a1      b3      0.6         3
  
  a1      b4      0.7         58
  
  a2      b5      0.5         63
  
  f0      a0      0.6         9
  
  f0      a1      0.8         5
  
  f0      a2      0.5         5
  
  a0      b0      0.2         6
  
  b5      c0      0.6         4
  </code></pre>
  
  <p>I need to do recursive parent child relationship and need to find all parents with a given child. However, I also need to multiply the values with each other for a give parent and child combination.</p>
  
  <p><strong>Expected output</strong>             </p>
  
  <pre><code>Root    Parent  Child   Path              Value 3 
  
  f0      b5      c1      f0/a2/b5/c1       0.5 * 0.5 * 0.3  (f0-&gt;a2 * a2-&gt;b5 * b5-&gt;c1)
  
  f0      a0      b0      f0/a0/b0          0.6 * 0.2  (f0-&gt;a0 * a0-&gt;b0)
  
  f0      a1      b4      f0/a1/b4          ..and so on
  
  f0      a1      b3      f0/a1/b3    
  
  f0      b5      c0      f0/a2/b5/c0 
  
  f0      a0      b2      f0/a0/b2    
  
  f0      a0      b1      f0/a0/b1
  </code></pre>
  
  <p>I am using the following code which works perfectly fine. I got this code from this site only. However, I am not able to figure out how to get the value 3 by multiplying the value 1 as a recourse through the path.</p>
  
  <pre><code>parents = set() children = {} for c,p in ancestry:
      parents.add(p)
      children[c] = p
  
  def ancestors(p):
      return (ancestors(children[p]) if p in children else []) + [p] 
  </code></pre>
  
  <blockquote>
    <p>for k in (set(children.keys()) - parents):
        print ('/'.join(ancestors(k)))</p>
  </blockquote>
  
  <p>any help is greatly appreciated.</p>