直接上代码:
import pandas as pd
import os
import re
import argparse
# 获取目录下的excel文件
def getExcel(dataPath, excelPath):
for maindir, subdir, file_name_list in os.walk(excelPath):
for filename in file_name_list:
data = {}
apath = os.path.join(maindir, filename)
file_path = apath.replace("\\", "/")
df = pd.read_excel(file_path)
df = pd.DataFrame(df, columns=['姓名', '证件号码'])
for i in df.values:
data[i[0]] = i[1]
print(data)
modifyName(data, dataPath)
# 修改文件名
def modifyName(data, dataPath):
try:
for maindir, subdir, file_name_list in os.walk(dataPath):
for filename in file_name_list:
try:
apath = os.path.join(maindir, filename)
file_path = apath.replace("\\", "/")
st