根据我的开始日期和结束日期,我有一个正确的周数列表。然后,使用这些周数,我想遍历主目录以加载每个文件并直接附加它们
这是我的密码:
os.chdir("C:\\Users\\shakir\\Desktop\\FY20") #directory
start_date = pd.to_datetime('2019/1/1') #Input date
end_date = pd.to_datetime('2019/2/1') #Input date
data_file = 'C:\\Users\\shakir\\Desktop\\FY20'
sched = pd.read_csv("C:\\Users\\shakir\\Desktop\\FY20\\wm_sched.csv", parse_dates=[1,2])
# determine what weeks to load into dataframes
month = 1
weeks = []
for i in sched.index:
if (month == sched.loc[i,'start_incl'].month) | (month == sched.loc[i,'end_excl'].month):
weeks.append(sched.loc[i,'weeknum'])
all_files = []
spath = r'C:\\Users\\shakir\\Desktop\\FY21'
filename = os.listdir(spath)
for f, item in enumerate(filename):
if (weeks == filename[f+1, 'date']):
all_files.append(filename[f+1, 'date'])
print(all_files)
我希望将日期范围的输出选为excel中的一个文件
目前没有回答
相关问题 更多 >
编程相关推荐