首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用熊猫分割成栏

用熊猫分割成栏
EN

Stack Overflow用户
提问于 2022-03-10 22:09:52
回答 1查看 24关注 0票数 0

我有一个带有4个可见列的数据文件,我试图用熊猫来分割它们。我要去找ParserError: Error tokenizing data. C error: Expected 3 fields in line 3, saw 8

这是我的资料

代码语言:javascript
复制
0.001155672            259,439      branch-instructions                                         
 0.001155672          1,266,239      instructions              #    1.10  insn per cycle         
 0.001155672             24,148      cache-references                                            
 0.001155672             11,586      cache-misses              #   47.979 % of all cache refs    
 0.001155672          1,150,999      cpu-cycles                                                  
 0.001155672              8,888      branch-misses             #    3.43% of all branches        
 0.002370509            381,074      branch-instructions                                         
 0.002370509          1,908,560      instructions              #    1.12  insn per cycle         
 0.002370509             29,034      cache-references                                            
 0.002370509             15,362      cache-misses              #   52.910 % of all cache refs    

我试过使用data = pd.read_table('repg.txt',sep='\s+', header=None, thousands=',')delim_whitespace=True

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-10 22:15:48

只需将comment='#'添加为pd.read_table的参数即可

代码语言:javascript
复制
data = pd.read_table('repg.txt',sep='\s+', header=None, thousands=',', comment='#')
print(data)

# Output
          0        1                    2
0  0.001156   259439  branch-instructions
1  0.001156  1266239         instructions
2  0.001156    24148     cache-references
3  0.001156    11586         cache-misses
4  0.001156  1150999           cpu-cycles
5  0.001156     8888        branch-misses
6  0.002371   381074  branch-instructions
7  0.002371  1908560         instructions
8  0.002371    29034     cache-references
9  0.002371    15362         cache-misses
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71431388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档