title: Read Word Document and get text for each heading
body: <p>I have a Microsoft word document and I need to extract the text and structure it into a data frame by each section of the document. Each section of the document starts with a Heading. The heading is formatted in Word as "Heading 2". For example:</p>
  
  <blockquote>
    <p><strong>This is section one</strong></p>
    
    <p>This is the text for the first section.</p>
    
    <p><strong>This is the second section of the document</strong></p>
    
    <p>And this is the text for the second section.</p>
  </blockquote>
  
  <p>I need to get the text for each section in a data frame where in column A I would have the section name and in column B I would have the section text.</p>
  
  <p>I am new to Python and I am trying <code>docx</code> package but the only think I was able to do was to get the full text based on a function I found in stackoverflow</p>
  
  <p><strong>Function (readDocx):</strong></p>
  
  <pre><code>#! python3
  from docx import Document
  
  def getText(filename):
      doc = Document(filename)
      fullText = []
      for para in doc.paragraphs:
          fullText.append(para.text)
      return '\n'.join(fullText)
  </code></pre>
  
  <p><strong>Code to  get the text:</strong></p>
  
  <pre><code>import readDocx
  
  test = readDocx.getText('THE FILE.docx')
  </code></pre>
  
  <p>I was able to find this loop that identifies the headings. The problem is how to iterate through the document and get each heading and text in a dataframe :</p>
  
  <pre><code>from docx import Document
  from docx.shared import Inches
  
  
  docs = Document("THE FILE.docx")
  
  for paragraph in docs.paragraphs:
      if paragraph.style.name=='Heading 2':
          print (paragraph.text)
  </code></pre>