title: Pandas: How to store cProfile output in a pandas DataFrame?
body: <p>There already exist some posts discussing python profiling using cProfile, as well as the challenges of analyzing the output due to the fact that the output file <strong>restats</strong> from the sample code below is not a plain text file. The snippet below is only a sample from <a href="https://docs.python.org/2/library/profile.html" rel="nofollow noreferrer">docs.python.org/2/library/profile</a>, and not directly reproducible.</p>
  
  <pre><code>import cProfile
  import re
  cProfile.run('re.compile("foo|bar")', 'restats')
  </code></pre>
  
  <p>There is one discussion here: <a href="https://stackoverflow.com/questions/21470217/profile-a-python-script-using-cprofile-into-an-external-file?rq=1">Profile a python script using cProfile into an external file</a>, and on the <a href="https://docs.python.org/2/library/profile.html" rel="nofollow noreferrer">docs.python.org</a> there are more details on how to analyze the output using <strong>pstats.Stats</strong> (still only a sample, and not reproducible):</p>
  
  <pre><code>import pstats
  p = pstats.Stats('restats')
  p.strip_dirs().sort_stats(-1).print_stats()
  </code></pre>
  
  <p>I may be missing some very important details here, but I would really like to store the output in a <strong>pandas DataFrame</strong> and do further analysis from there. </p>
  
  <p>I thought it would be pretty simple since the output in iPython from running <code>cProfile.run()</code> looks fairly tidy:</p>
  
  <pre><code>In[]:
  cProfile.run('re.compile("foo|bar")'
  
  Out[]:
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kwC3q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kwC3q.png" alt="enter image description here"></a></p>
  
  <p>Any suggestions on how to get this into a pandas DataFrame in the same format?</p>