0

I have a .tsv file dataset, and I transformed it into a DataFrame using Pandas. Imagine that my_tsv_file was something like:

A Apple
B Orange
C Pear

To build the DataFrame I used:

df = pandas.read_csv(my_tsv_file, sep='\t')

Now, the first row of my_tsv_file was originally a row part of the data, but it has been transformed to the "key row" in the new DataFrame. So now the Dataframe is something like:

      A Apple
   0  B Orange
   1  C Pear

As "A" and "Apple" were keys, when they actually are not. I would like to add the correct "key row", in order to obtain something like:

      ID Fruit
   0  A  Apple
   1  B  Orange
   2  C  Pear

How can I achieve this? I can't modify the original .tsv file. Please remind that I am at the very beginning with Python and Pandas.

albero123
  • 77
  • 1
  • 7
  • 1
    Does this answer your question? [How to add header row to a pandas DataFrame](https://stackoverflow.com/questions/34091877/how-to-add-header-row-to-a-pandas-dataframe) – Chris Jan 10 '20 at 17:20

1 Answers1

0

have you tried

df = pandas.read_csv(my_tsv_file, sep='\t', names=['ID', 'Fruit'])

Kenan
  • 13,156
  • 8
  • 43
  • 50