Skip to main content
 首页 » 编程设计

python之Pandas 如何跳过读取csv文件列表的空文件

2024年10月01日6thcjp

我有 60 个 csv 文件:

fname[i]  i=0:59 
while fname[19] (or maybe some other file) is empty 

如何将它们读取到列表中而不会出现错误“pandas.errors.EmptyDataError:没有要从文件中解析的列”?

请您参考如下方法:

使用 try 并捕获异常。

try: 
    # read your files 
except pandas.errors.EmptyDataError: 
    pass