0

I have a file test.tsv with some rows having quotes and it basically skips stops using the new line character as a new row indicator. So if I have a file

" m 1 what does comoda mean 1 the poke co 1 dmf 1 "g 1 

and I use

test = pd.read_csv("test.tsv", sep='\t') 

I get the all rows as one row

 m\t1\nwhat does comoda mean\t1\nthe poke co\t1\ndmf\t1\ng 1 

I want to keep all rows intact and get the output

" m 1 what does comoda mean 1 the poke co 1 dmf 1 "g 1 

Is there a way to solve this double quote issue? I have multiple rows coming out as a single row wherever I have double quotes opened up until there is double quote to close that. After that the rows are interpreted correctly.

6
  • Can you provide an example dataframe containing exactly the output you want? I'm not clear on what you mean by "get the output like we have the input". Commented May 11, 2020 at 22:09
  • \n means a new line. is this your whole tsv file? Commented May 11, 2020 at 22:10
  • No I just put a sample in. Commented May 11, 2020 at 22:12
  • Basically I have multiple rows and all of them now are coming out as one row after reading. Commented May 11, 2020 at 22:14
  • Separator in your csv file is \t ?? Commented May 11, 2020 at 22:20

1 Answer 1

1

You can control the parsing of quotes using the quoting keyword parameter of pandas.read_csv. In your case you can disable quoting like so:

>>> import pandas as pd >>> import csv >>> pd.read_csv("test.tsv", sep='\t', quoting=csv.QUOTE_NONE) " m 1 0 what does comoda mean 1 1 the poke co 1 2 dmf 1 3 "g 1 

Note that the first row is being interpreted as a column header. Pass header=None to prevent that.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.