Python pandas read_csv does not recognize \ t in tab delimited file

I am trying to read individual data in pandas in the next tab:
test.txt:

col_a\tcol_b\tcol_c\tcol_d
4\t3\t2\t1  
4\t3\t2\t1 

I import test.txt as follows:

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

The resulting framework has 1 column. \ T is not recognized as a tab.

If I replace \ t with the "keyboard tab", the file will be parsed correctly. I also tried replacing '\ t with \ t and / t and no luck.

Thanks in advance for your help. Lobster

PS: Screenshot of http://imgur.com/a/nXvW3

+4
source share
1 answer

\t , t. a tab. escape- sep.

pd.read_csv('test.txt', sep=r'\\t', engine='python')

   col_a  col_b  col_c  col_d
0      4      3      2      1
1      4      3      2      1

pd.read_csv('test.txt', sep='\\\\t', engine='python')

   col_a  col_b  col_c  col_d
0      4      3      2      1
1      4      3      2      1

r , , . , . , .

+4

Source: https://habr.com/ru/post/1682782/


All Articles