简体   繁体   English

Python / Pandas-根据文件名中的日期读取文件夹中的多个文件

[英]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.

相关问题 Python 3.5:根据文件名将文件移动到文件夹 - Python 3.5: Moving files to folder based on filenames Python:根据文件名将文件移动到文件夹 - Python: Moving files to folder based on filenames Python更改文件夹中多个文件的文件名 - Python changing filenames of multiple files in a folder Python,easyGUI和sqlite3:使用python读取一个文件夹或多个文件夹中的文件,然后将文件夹名称和文件名添加到数据库 - Python, easyGUI and sqlite3: Using python to read files in one folder or multiple folder, then adding the folder names and filenames to database 基于日期将数据导出到多个 excel 文件 python pandas - export data to multiple excel files based on dates python pandas 在文件夹Python中读取两个日期之间的文件 - Read files between two dates in a folder Python 在python中读取多个文件并将文件名和内容组合成一个数据帧 - Read multiple files in python and combine filenames and content into a dataframe 将文件夹中的多个excel文件读入pandas - Read multiple excel files from a folder into pandas Pandas python 多次导出读取文本文件 - Pandas python multiple export read text files Python Pandas-根据多个日期用多列中的NAN替换值? - Python Pandas - replace values with NAN in multiple columns based on mutliple dates?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM