以下是以下文件夹中的文件:
C:emporary_location ile_name_20240901.csv C:emporary_location ile_name_20240902.csv C:emporary_location ile_name_20240903.csv C:emporary_location ile_name_20240904.csv C:emporary_location ile_name_20240905.csv C:emporary_location ile_name_20240906.csv C:emporary_location ile_name_20240907.csv C:emporary_location ile_name_20240908.csv C:emporary_location ile_name_20240909.csv C:emporary_location ile_name_20240910.csv C:emporary_location ile_name_20240911.csv C:emporary_location ile_name_20240912.csv C:emporary_location ile_name_20240913.csv
这是我用来仅选择一个文件的代码,它只会读取该文件,
import pandas as pd, numpy as np
from numpy import *
import glob
import os
import os.path
import duckdb
_path = r'C: emporary_location\'
_frame = []
for loc in glob.glob(_path + '*.csv'):
if "20240905" in loc:
print('Loading', loc)
data = pd.read_csv(loc, low_memory=False)
如何使用上面相同的代码来选择日期大于特定日期的文件? 例如:
for loc in glob.glob(_path + '*.csv'):
if 20240905 > loc:
print('Loading', loc)
data = pd.read_csv(loc, low_memory=False)
代码应打印以下文件。
C:emporary_location ile_name_20240906.csv C:emporary_location ile_name_20240907.csv C:emporary_location ile_name_20240908.csv C:emporary_location ile_name_20240909.csv C:emporary_location ile_name_20240910.csv C: emporary_location ile_name_20240911.csv C:emporary_location ile_name_20240912.csv C:emporary_location ile_name_20240913.csv
尝试获取最后 8 位数字,不包括
.csv
if int(loc[-12:-4]) > 20240905: