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.

1

1 Answer 1

1

have you tried

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

Sign up to request clarification or add additional context in comments.

2 Comments

I don't think you need to do that, by supplying names pandas will understand there is no header
Thanks! I didn't know this option, is exactly what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.