title: Pandas - How to create a one row dataframe using multiple columns of another dataframe
body: <p>I have searched how to "create a one row dataframe using multiple columns of another dataframe" all over stack overflow and other sites but I am only getting subjects like "how to merge columns" or "how to concatenate dataframes". But I have not seen how to merge column names.</p>
  
  <p>I have <code>tsv</code> files that I import in python using <code>Pandas</code>. The dataframes are like this :</p>
  
  <pre><code>min_mz_parent | max_mz_parent | mz_bin | intensity
  
       405      |      415      |   999  |    750
       405      |      515      |  1000  |    5482
       405      |      515      |  1001  |    6487
                               ...
       705      |      715      |  999   |    847
       705      |      715      |  1000  |   12546
  </code></pre>
  
  <p>I have 160 files with this kind of writing. I would like to iterate over all of them and then concatenate the value of the <code>column 1, 2 and 3</code> to create the name of a new column in a new data frame and the value corresponding to this new column would be <code>the value of the 4th column</code> in the first dataframe.
  At the end, I would like the final dataframe to be like this (if there is one file, and more rows if there are more files used) :</p>
  
  <pre><code>405_415_999 | 405_415_1000 | 405_415_1001 | ... | 705_715_999 | 705_715_1000_12546
       750    |     5482     |    6487      | ... |     847     |       12546
  </code></pre>
  
  <p>I already have a functional code. It works on small files (500ko) but it takes a LOT of time when I want to apply it to huge files : modify and then concatenate 160 tsv files of 120Mo each.</p>
  
  <p>I heard that using <code>iterrows()</code>, I could lose a lot of time and I should use <code>vectorization</code> but I still do not understand how to do it with my problem.</p>
  
  <p>Here is the code I have for now (I did not import the first if statement that check <code>args</code> because it does not involve my problem of dataframe :</p>
  
  <pre><code>tsv_list = glob.glob(args.dir + '*.tsv')
  
  concat_tsv = pd.DataFrame()
  
  count_file = 1
  
  elif args.MS == 'MS2':
      for file in tsv_list:
          name = {'sample': file.split('/')[-1]}
          if 'high_J' in name['sample']:
              continue
  
          # Define target class name
          if name['sample'].split('_')[0:1][0] in ['UP', 'SS', 'SM', 'SH','SE','SA','PM','PA','KP','KO','EF','EA','CF']:
              target_class = [name['sample'].split('_')[0:1][0]]
          elif name['sample'].split('_')[0:1][0] in ['SAu', 'ECl']:
              target_class = name['sample'].split('_')[0:1][0]
          elif 'Blanc' in name['sample']:
              target_class = ['Blank']
          else :
              target_class = ['']
              print('Wrong name : '+name['sample'])
  
          print('Currently converting and adding : ' + name['sample'] + ' ### File n°' + str(count_file))
  
          tsv = pd.read_csv(file, sep='\t')
  
          # Create temporary pandas dataframe for each file
          tmp = pd.DataFrame(name, index=[0])
          tmp['target'] = target_class
  
          #  Iterate on each dataframe file and extract information
          for index, row in tsv.iterrows():
              mz = str(row['min_mz_parent']) + "_" + str(row['max_mz_parent']) + '_' + str(row['mz_bin'])
              row_df = [row['intensity']]
              tmp[mz] = row_df
  
          concat_tsv = pd.concat([concat_tsv, tmp], axis=0, ignore_index=True)
  
          count_file += 1
  </code></pre>
  
  <p>If you want more information to help me, please let me know.
  I wish you a good day.</p>
  
  <p>ElsaC</p>