title: Follow up - Creating new columns based on value from another column in pandas
body: <p>Follow up from my previous question -- <a href="https://stackoverflow.com/questions/59483651/creating-new-columns-based-on-value-from-another-column-in-pandas">Creating new columns based on value from another column in pandas</a></p>
  
  <p><strong>My goal now is :</strong></p>
  
  <pre><code>Code    Name        Level1    Level1Name    Level2  Level2Name  Level3  Level3Name
  0   A   USA             A       USA             
  1   AM  Massachusetts   A       USA          AM     Massachusetts   
  2   AMB Boston          A       USA          AM     Massachusetts   AMB     Boston
  3   AMS Springfield     A       USA          AM     Massachusetts   AMS     Springfiled
  4   D   Germany         D   Germany          
  5   DB  Brandenburg     D   Germany          DB     Brandenburg     
  6   DBB     Berlin      D   Germany          DB     Brandenburg     DBB     Berlin
  7   DBD     Dresden     D   Germany          DB     Brandenburg     DBD     Dresden
  </code></pre>
  
  <p>Building on Scott Boston's code, I have so far:</p>
  
  <pre><code>match   0   1   2
  0       A   A   A
  1       A   AM  AM
  2       A   AM  AMB
  3       A   AM  AMS
  4       D   D   D
  5       D   DB  DB
  6       D   DB  DBB
  7       D   DB  DBD
  </code></pre>
  
  <p>My approach is to loop through each column and remove row that doesn't have the same length as the rest of the values in that column but cannot seem to figure out the logic. </p>
  
  <p><strong>Sample Code:</strong> </p>
  
  <pre><code>df = pd.read_excel(r'/Users/BoBoMann/Desktop/Sequence.xlsx')
  
  df['Codes'] = [[*i] for i in df['Code']]
  df_level = df['Code'].str.extractall('(.)')[0].unstack('match').fillna('').cumsum(axis=1)
  df_level
  </code></pre>
  
  <p>Thank you for your help! </p>