[英]Python/Pandas - Read multiple files in a folder based on dates in filenames
I have a folder with hundreds of csv files with the filenames in the format of file_nameddmmyyyy (eg data25062019.csv). 我有一个包含数百个csv文件的文件夹,其文件名的格式为file_nameddmmyyyyy(例如data25062019.csv)。
I am using python/pandas to read the files and manipulating the dataframes. 我正在使用python / pandas读取文件并处理数据框。 I want to be able to pull multiple csv files based on the dates on the file names.
我希望能够根据文件名上的日期拉出多个csv文件。 eg I want to open the daily files from the previous one week and append them to a dataframe.
例如,我想打开前一周的每日文件并将它们附加到数据框。
The problem is there are not files for everyday of the week, so there may only be 4-5 files for the last week. 问题是一周中的每一天都没有文件,因此上周可能只有4-5个文件。
Any suggestions on best way to approach this? 关于解决此问题的最佳方法有何建议?
只需将read命令放入try try语句中即可:
try: read_file() append_file() except: pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.