title: Convert txt file, with variable categories, to dictionary and pandas df
body: <p>I've converted a txt file that has a fixed number of variables, for every entry, to a dict and df.  For example, if every entry in the txt file has a Date entry followed by Category A, Category B, and Category C, it has a set number of variables.  In my current question, there are many categories but most are empty (NaN). I don't want to carry the null value category entries in the txt file.  In this case, the txt file may have one Date entry with only Category A and Category C, and another Date entry with only Category B.  In the final df, each date is a row and some columns of that row are NaN.  My problem is reading that txt file, with unlisted categories in some entries, produces a &quot;All arrays must be of the same length&quot; error.</p>
  <p>For example, I've read this txt file:</p>
  <pre><code>Date: Jan 1
  Cat A: 5
  Cat B: 8
  Cat C:  2
  
  Date: Feb 6
  Cat A: 7
  Cat B: 2
  Cat C: 3
  
  etc...for multiple dates.
  
  with open ('text.txt', &quot;r&quot;) as file:
      df = file.read()
  
  date = re.findall('Date:(.*?)\n', df)
  col_a = re.findall('Cat A:(.*?)\n', df)
  col_b = re.findall('Cat B:(.*?)\n', df)
  col_c = re.findall('Cat C:(.*?)\n', df)
  
  dic = {'Date':date, 'Col A': col_a, 'Col B': col_b, 'Col C': col_c}
  </code></pre>
  <p>This works fine when the txt file always contains Cat A, B, &amp; C.  In another case, I have many categories, and the text file would be unnecessarily messy to carry them all when there is no entry.  I want to read this txt:</p>
  <pre><code>Date: Jan 1
  Cat A: 1
  Cat F: 5
  
  Date: Jan 10
  Cat F: 6
  
  Date: Dec 5
  Cat A: 8
  Cat B: 5
  Cat E: 7
  Cat F: 1 
  </code></pre>
  <p>In the final df, each row can have Nan values where the cat wasn't in the entry.</p>