2016-11-19 117 views
1

当文件夹中存在文件时,出现文件不存在的错误,请问我在哪里犯了错误?熊猫无法聚合

pd.DataFrame.from_csv 

我收到如下所示的错误。

Traceback (most recent call last): 
    File "main.py", line 194, in <module> 
    start_path+end_res) 
    File "/Users/admin/Desktop/script/mergeT.py", line 5, in merge 
    df_peak = pd.DataFrame.from_csv(peak_score, index_col = False, sep='\t') 
    File "/Library/Python/2.7/site-packages/pandas/core/frame.py", line 1231, in from_csv 
    infer_datetime_format=infer_datetime_format) 
    File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 645, in parser_f 
    return _read(filepath_or_buffer, kwds) 
    File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 388, in _read 
    parser = TextFileReader(filepath_or_buffer, **kwds) 
    File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 729, in __init__ 
    self._make_engine(self.engine) 
    File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 922, in _make_engine 
    self._engine = CParserWrapper(self.f, **self.options) 
    File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 1389, in __init__ 
    self._reader = _parser.TextReader(src, **kwds) 
    File "pandas/parser.pyx", line 373, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:4175) 
    File "pandas/parser.pyx", line 667, in pandas.parse**strong text**r.TextReader._setup_parser_source (pandas/parser.c:8440) 
IOError: File results\scoring\fed\score_peak.txt does not exist 

我已经尝试的路径设置为确切的文件 例如

+0

第一个错误:脚本的缩进错误。然后:backslaches而不是斜杠。可能您使用的是过时的文件,可能是在Windows中配置的。 – user3159253

+0

像@ user3159253表示你需要在函数'def'后面缩进所有内容,否则文件路径不会被改变。 –

+0

@ user3159253您的意思是我导入数据,如peak_score ='\ Users \ admin \ Desktop \ peak_score.txt'?是的,它是基于Windows,现在我使用Mac –

回答

2

documentation of pandas 0.19.1pandas.DataFrame.from_csv不支持index_col = False。尝试使用pandas.read_csv代替(使用相同的参数)。还要确保你使用的是熊猫的最新版本。

见,如果这个工程:

import pandas as pd 
def merge(peak_score, profile_score, res_file): 
    df_peak = pd.read_csv(peak_score, index_col = False, sep='\t') 
    df_profile = pd.read_csv(profile_score, index_col = False, sep='\t') 
    result = pd.concat([df_peak, df_profile], axis=1) 
    print result.head() 
    test = [] 
    for a,b in zip(result['prot_a_p'],result['prot_b_p']): 
     if a == b: 
      test.append(1) 
     else: 
      test.append(0) 
    result['test']=test 
    result = result[result['test']==0] 
    del result['test'] 
    result = result.fillna(0) 
    result.to_csv(res_file) 

if __name__ == '__main__': 
    pass 

关于改变从Windows到OS X时的路径问题:

在Unix中的所有口味,路径都写有斜线/,而在Windows反斜杠\被使用。由于OS X是Unix的后裔,正如其他用户已经正确指出的那样,当您从Windows更改时,您需要调整路径。

+0

辉煌!谢谢 –