Unable to read csv in pandas with sys.argv[]

时间:2016-12-09 13:07:11

标签: python-2.7 pandas

I read a csv file in pandas by specifying the name directly. It works without trouble. But when I try to do the same with sys.argv[] it throws an error. This is what I tried.

import sys
import pandas as pd

filename = sys.argv[-1]

data = pd.read_csv(filename, delimiter=',')
print data
print data[data['logFC'] >= 2]

The error it throws back is:

Traceback (most recent call last):   File "/Users/filter_cutoff_genexdata.py", line 7, in <module>
    data = pd.read_csv(filename, delimiter=',')   File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 498, in parser_f
    return _read(filepath_or_buffer, kwds)   File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 285, in
_read
    return parser.read()   File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 747, in read
    ret = self._engine.read(nrows)   File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 1197, in read
    data = self._reader.read(nrows)   File "pandas/parser.pyx", line 766, in pandas.parser.TextReader.read (pandas/parser.c:7988)   File "pandas/parser.pyx", line 788, in pandas.parser.TextReader._read_low_memory (pandas/parser.c:8244)   File "pandas/parser.pyx", line 842, in pandas.parser.TextReader._read_rows (pandas/parser.c:8970)   File "pandas/parser.pyx", line 829, in pandas.parser.TextReader._tokenize_rows (pandas/parser.c:8838)   File "pandas/parser.pyx", line 1833, in pandas.parser.raise_parser_error (pandas/parser.c:22649) pandas.parser.CParserError: Error tokenizing data. C error: Expected 1 fields in line 7, saw 3

Can anyone please tell why it doesn't work ?

0 个答案:

没有答案