简体   繁体   English

EmptyDataError:在字典中加载多个文件时没有要从文件中解析的列

[英]EmptyDataError: No columns to parse from file when loading several files in a dictionary

I have 1000 csv files that I call using the following code (which puts every file into a dictionary):我有 1000 个 csv 文件,我使用以下代码(将每个文件放入字典)调用它们:

dataframes = {}
csv_root = Path(".")
for csv_path in csv_root.glob("*.csv"):
key = csv_path.stem
dataframes[key] = pd.read_csv(csv_path, skiprows=1)

However when I use this code I got this error但是,当我使用此代码时,出现此错误

EmptyDataError: No columns to parse from file

Which indicates that there is empty data or header is encountered.这表明遇到空数据或标题。

I would like to know how to identify which of those 1000 csv files are the ones causing troubles?我想知道如何识别这 1000 个 csv 文件中的哪些是造成问题的文件? Because, as you can understand, checking file by file will consume a lot of time.因为,正如您所理解的,逐个文件检查会消耗大量时间。

Thanks a lot!非常感谢!

I would just use a try/catch, like so:我只会使用 try/catch,如下所示:

dataframes = {}
csv_root = Path(".")
for csv_path in csv_root.glob("*.csv"):
    key = csv_path.stem
    try:
        dataframes[key] = pd.read_csv(csv_path, skiprows=1)
    except Exception, as e:
        dataframes[key] = 'error' # mark the errored

This last step will get you the stems with issues:最后一步将使您了解问题的根源:

errored_stems = [k for k,v in dataframes.iteritems() if k == 'error']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有要从文件中解析的列 (EmptyDataError: ) - No columns to parse from file (EmptyDataError: ) EmptyDataError:没有要从文件中解析的列 - EmptyDataError: No columns to parse from file EmptyDataError:没有要从文件中解析的列 - EmptyDataError : No columns to parse from file EmptyDataError 没有要从文件中解析的列 - EmptyDataError No columns to parse from file 将目录中的所有文件连接到单个 CSV 时,Pandas 中的“EmptyDataError:没有要从文件中解析的列” - 'EmptyDataError: No columns to parse from file' in Pandas when concatenating all files in a directory into single CSV EmptyDataError:从 S3 存储桶读取多个 csv 文件到 Pandas Dataframe 时,没有要从文件解析的列 - EmptyDataError: No columns to parse from file when reading multiple csv files from S3 bucket to pandas Dataframe EmptyDataError:没有要从关于 streamlit 的文件中解析的列 - EmptyDataError: No columns to parse from file about streamlit Pandas - EmptyDataError:读取库存 .csv 文件时没有要从文件中解析的列 - Pandas - EmptyDataError: No columns to parse from file when reading stock .csv file 无法读取.csv 文件。 EmptyDataError:没有要从文件中解析的列 - Cant read .csv file. EmptyDataError: No columns to parse from file pandas.errors.EmptyDataError:没有要从文件中解析的列 - pandas.errors.EmptyDataError: No columns to parse from file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM