title: Can I write an efficient function to do this?
body: <p>My purpose is to split the column into columns separated by <code>|</code> and concatenate the resulting columns to the existing data frame, however, it is inefficient to do so with the below:</p>
  
  <pre><code>new = df4['mts_path'].str.split('|', expand=True)
  df4['mts_path1'] = new[0]
  df4['mts_path2'] = new[1]
  df4['mts_path3'] = new[2]
  df4['mts_path4'] = new[3]
  df4['mts_path5'] = new[4]
  df4['mts_path6'] = new[5]
  df4['mts_path7'] = new[6]
  </code></pre>
  
  <p>Any advice to write a function with loops to achieve that?</p>