我有一个文件夹,其中包含可变数量的文件,并且每个文件的名称中都有可变字符串。例如:
my_file V1.csv
my_file V2.csv
my_file something_else.csv
我需要:
现在,我对每个文件使用单独的pd.read_csv函数,然后将它们与连接符合并。
这不是最佳选择,因为每次源文件夹中的文件更改时,我都需要修改脚本。
是否可以自动执行此过程,以便即使源文件发生更改也可以正常工作?
答案 0 :(得分:0)
for filename in os.listdir(directory):
if filename.startswith("my_file") and filename.endswith(".csv"):
# do some stuff here
continue
else:
continue