简体   繁体   中英

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+' :

df = pd.read_csv('path_to_folder/test.bed', sep='\s+',header=0,index_col=0)

Or use parameter delim_whitespace :

df = pd.read_csv('path_to_folder/test.bed', delim_whitespace=True, header=0,index_col=0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM