EmptyDataError:导入许多csv文件时,没有列可从文件python解析

时间:2019-06-04 09:18:32

标签: python pandas python-2.7

我正在从一个文件夹导入csv文件,每个文件每10个复制一行。第一行和两列(日期时间,值)有标头,以逗号分隔。当我为单个文件运行代码时,它可以按预期工作:

frequency=pd.read_csv("DK_Frequency/2019-04-11.csv")
li = []
li.append(frequency.iloc[::10])
li

                 Time             Value
0       2019-04-11 00:00:00.000  50.022
10      2019-04-11 00:00:01.000  50.023
20      2019-04-11 00:00:02.000  50.021
30      2019-04-11 00:00:03.000  50.022
40      2019-04-11 00:00:04.000  50.022
50      2019-04-11 00:00:05.000  50.023
60      2019-04-11 00:00:06.000  50.021
70      2019-04-11 00:00:07.000  50.023

当我使用以下方法进入文件夹时:

all_files = glob.glob("DK_Frequency/*.csv")
li = []
for i in range(len(all_files):
    frequency= pd.read_csv(all_files[i])
    li.append(frequency.iloc[::10])

甚至:

all_files = glob.glob("DK_Frequency/*.csv")
li = []
for file in all_files :
    frequency= pd.read_csv(file)
    li.append(frequency.iloc[::10])

我收到错误:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 646, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 389, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 730, in __init__
    self._make_engine(self.engine)
  File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 923, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 1390, in __init__
    self._reader = _parser.TextReader(src, **kwds)
  File "pandas/parser.pyx", line 538, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:5902)
pandas.io.common.EmptyDataError: No columns to parse from file

关于如何解决此问题的任何想法?

0 个答案:

没有答案