セパレータの任意の空白にはsep='s\+'
を追加する必要があります。これは、read_table
です。
デフォルトの区切り文字が,
であるため、すべてのデータが1つの列になるため、期待通りに機能しません。パラメータ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), 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
別の解決策:
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
あなたの助けをありがとう!私は以前これを無視しました。 –