1 Star 0 Fork 3

看到我请让我滚去学习/VisualizationProject

forked from Yiman/VisualizationProject 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
filter_file_path.py 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
walker 提交于 2021-03-11 19:31 . 修复潜在bug
import os
import re
"""
:param 清洗文件路径
:return 按时间顺序排列好的文件路径名
"""
def filter_file_path():
all_file = []
for i in os.walk('./data/stu_data'):
all_file.append(i)
dir_name = all_file[0][1]
max_compare_times = 3
dir_name = sort_by_date(dir_name, max_compare_times)
all_file = all_file[1:]
month_data_name = []
final_month_name = []
file_with_path = []
for i in all_file:
month_data_name.append(i)
for i in month_data_name:
final_month_name.append(i[-1])
dir_len = len(dir_name)
max_compare_times = 4
for i in range(0, dir_len):
final_month_name[i] = sort_by_date(final_month_name[i], max_compare_times)
for i in range(0, len(dir_name)):
for j in range(0, len(final_month_name[i])):
final_month_name[i][j] = './data/stu_data/' + str(dir_name[i]) + '/' + str(final_month_name[i][j])
file_with_path = file_with_path + final_month_name[i]
return file_with_path
"""
:param 用正则,选择排序
:return 按日期排序好的列表
"""
def sort_by_date(data, times):
# 文件夹路径不同,选择不同匹配模式
patt = '(\d+)-(\d+)' if times == 3 else '(\d+)-(\d+)-(\d+)'
# 交换排序
for i in range(len(data) - 1):
for x in range(i + 1, len(data)):
j = 1
while j < times:
lower = re.search(patt, data[i]).group(j)
upper = re.search(patt, data[x]).group(j)
# print lower,upper
if int(lower) < int(upper):
j = times
elif int(lower) == int(upper):
j += 1
else:
data[i], data[x] = data[x], data[i]
j = times
return data
if __name__ == '__main__':
file_name_with_path = filter_file_path()
for i in file_name_with_path:
print(i)
print('count:', len(file_name_with_path))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/blog52/visualization-project.git
git@gitee.com:blog52/visualization-project.git
blog52
visualization-project
VisualizationProject
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385