[英]why am i getting an empty data frame in pandas?
I wish to read a tab-delimited file with pandas. 我希望读取一个以制表符分隔的大熊猫文件。 I have used the following code:
我使用了以下代码:
df = pd.read_csv('path_to_folder/test.bed', sep='\t',header=0,index_col=0)
However, the resulting data frame is empty and looks something like this: 但是,结果数据框为空,看起来像这样:
Empty DataFrame
Columns: []
Index: [loc.00001 100 150, loc.00002 200 210 ..... ]
I wish to produce a data frame that includes a header present in this file. 我希望产生一个包含此文件中存在的标头的数据框。
TSS TES
Loci
loc.00001 100 150
loc.00002 200 210
Any ideas why I am getting an empty data frame would be useful. 为什么我得到一个空的数据框的任何想法都是有用的。 Thank you.
谢谢。
It seems your separator is not tab
, but whitespace
, so need sep='\\s+'
: 看来您的分隔符不是
tab
,而是whitespace
,所以需要sep='\\s+'
:
df = pd.read_csv('path_to_folder/test.bed', sep='\s+',header=0,index_col=0)
Or use parameter delim_whitespace
: 或使用参数
delim_whitespace
:
df = pd.read_csv('path_to_folder/test.bed', delim_whitespace=True, header=0,index_col=0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.