# -coding: utf-8 -*
"""
该脚本用来读取excel表格指定数据并返回所在行列值,
将对应行列值的txt文件读取归档到gsmap_result文件夹
A: 大于1500
B: 1300-1500
C:小于1300
"""
import pandas as pd
import os
import numpy as np
import shutil
def read_txt(path):
filelist = os.listdir(path)
file_names = np.array([file.split('_')[1] for file in filelist if file.endswith('.txt')], dtype=object)
return filelist,file_names
#对数据进行分区
def divide2A_B_C(path_excel):
df = pd.read_excel(path_excel)
A = []
B = []
C = []
index_A = []
index_B = []
index_C = []
for row in range(df.shape[0]):
for col in range(df.shape[1]):
if df.ix[row][col] >= 1500 and df.ix[row][col] != -9999:
A.append(df.ix[row][col])
index_A.append(('%02d' + '%02d') % (row + 2, col + 1))
elif 1300 <= df.ix[row][col] < 1500:
B.append(df.ix[row][col])
index_B.append(('%02d' + '%02d') % (row + 2, col + 1))
else:
C.append(df.ix[row][col])
index_C.append(('%02d' + '%02d') % (row + 2, col + 1))
return index_A, index_B, index_C
#找寻相同后缀名文件并复制到相应文件夹
def findall_file(divide_list, filelist, filename, path_result_x, path_txt):
for i in divide_list:
if i+'.txt' in filename:
src = path_txt + filelist[filename.index(i+'.txt')]
dst = path_result_x + filelist[filename.index(i+'.txt')]
shutil.copy(src, dst)
path_excel = 'DEM.xls'
path_txt = './gsmap_mvk/'
path_result = './gsmap_result/'
path_result_A = './gsmap_result/A/'
path_result_B = './gsmap_result/B/'
path_result_C = './gsmap_result/C/'
filelist,filename = read_txt(path_txt)
filename = list(filename)
x = filelist[filename.index('0212.txt')]
print(x)
index_A, index_B, index_C = divide2A_B_C(path_excel)
findall_file(index_A, filelist, filename, path_result_A, path_txt)
findall_file(index_B, filelist, filename, path_result_B, path_txt)
findall_file(index_C, filelist, filename, path_result_C, path_txt)
python 该脚本用来读取excel表格指定数据并返回所在行列值, 将对应行列值的txt文件读取归档到gsmap_result文件夹
最新推荐文章于 2024-07-01 09:17:46 发布