I got a file like this:
TCGA1 0 QWE
TCGA2 1 QWE
TCGA2 -2 RAF
TCGA3 2 KLS
and tried to read it into a dataframe using pandas.
You have to add sep='s\+'
for separator arbitrary whitespace in read_table.
It does not work as you expected, because default separator is ,
, so all data are in one column.
import pandas as pd
import io
temp=u"""TCGA1 0 QWE
TCGA2 1 QWE
TCGA2 -2 RAF
TCGA3 2 KLS"""
#after testing replace io.StringIO(temp) to filename
df = pd.read_table(io.StringIO(temp), sep="\s+", header=None)
print df
0 1 2
0 TCGA1 0 QWE
1 TCGA2 1 QWE
2 TCGA2 -2 RAF
3 TCGA3 2 KLS
Another solution with parameter delim_whitespace=True
:
import pandas as pd
import io
temp=u"""TCGA1 0 QWE
TCGA2 1 QWE
TCGA2 -2 RAF
TCGA3 2 KLS"""
#after testing replace io.StringIO(temp) to filename
df = pd.read_table(io.StringIO(temp), delim_whitespace=True, header=None)
print df
0 1 2
0 TCGA1 0 QWE
1 TCGA2 1 QWE
2 TCGA2 -2 RAF
3 TCGA3 2 KLS