1

I have a tab seperated csv file like below:

    1   2   3   4   5   6   7   8   9   10

    a   b   c   d   e   f   g   h   i   j

    k   l   m   n   o   p   q   r   s   t

And, I'm reading it to a dataframe with the below code

    df = pd.read_csv('C:/Users/IBM_ADMIN/Desktop/Delete/input1.csv',encoding='ANSI', delimiter='\t', header=0)

When I execute the above code I'm getting output like this image -> what_I_got

But, I'm expecting like this -> desired_output

I tried many ways to split the column but it's not working.Could you help me with a solution please?

3
  • It seems separator is , try remove delimiter='\t',, because default separator is , Commented Mar 13, 2018 at 7:37
  • It worked. Thanks a lot @jezrael Commented Mar 13, 2018 at 7:41
  • For anyone who actually has this issue (since the question was inaccurate in its assertions): if you're using double-quotes a la delimiter="\t", you're likely passing the delimiter as a literal t - try double-escaping it with delimiter="\\t" to actually get a tab character. Commented Nov 5, 2020 at 16:29

1 Answer 1

3

You need remove delimiter='\t' - separator is ,.

It working because default separator is ,, also is possible remove header=0 because if not parmeter names by default header=0:

df = pd.read_csv('C:/Users/IBM_ADMIN/Desktop/Delete/input1.csv',encoding='ANSI')
Sign up to request clarification or add additional context in comments.

Comments

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.