43 KiB
43 KiB
In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/交警支队最新名册.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
code = int(sheet.cell(n, 4).value)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 6).value
xb = str(sheet.cell(n, 7).value)
if xb == '1':
sex = '男'
elif xb =='2':
sex = '女'
dict1['sex'] = sex
dict1['unit'] = sheet.cell(n, 3).value
dict1['birth'] = str(sheet.cell(n,8).value).split(' ')[0]
person[code] = dict1
filename = 'data/交警支队名单221010.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
import os
import glob
import csv
fi_path = 'data/小鹅通/'
dict1 = {}
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
for fn in fl:
with open(fn,'r',newline='',encoding='gb18030') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
header = next(fl1)
for line in fl1:
#line = re.sub('[\r\n\f ]{1,}', '', line)
list1.append(line)
for item in list1:
dict1.setdefault(item[0],{})
dict1[item[0]]['nick'] = item[1]
dict1[item[0]]['name'] = item[4]
dict1[item[0]]['phone'] = item[5]
filename = 'data/小鹅通人员信息221010.json'
with open(filename,'w') as fl:
json.dump(dict1, fl,ensure_ascii=False) In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/新部门排序-淄博交警支队人员名单 _56473.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
phone = sheet.cell(n, 5).value
person.setdefault(phone, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
xb = str(sheet.cell(n, 3).value)
if xb == '1':
sex = '男'
elif xb =='2':
sex = '女'
dict1['sex'] = sex
dict1['unit'] = sheet.cell(n, 1).value
dict1['birth'] = str(sheet.cell(n,4).value).split(' ')[0]
person[phone] = dict1
filename = 'data/交警支队手机号码221010.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
filename = 'data/交警支队名单221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list2 = []
filename = 'data/交警支队手机号码221010.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k, v in dict2.items():
list1 = [k,v['name'],v['birth'],v['unit']]
list2.append(list1)
for k, v in dict1.items():
name = v['name']
birth = v['birth']
for item in list2:
if name in item and birth in item:
dict1[k]['phone'] = item[0]
dict1[k]['unit'] = item[3]
dict2[item[0]]['code'] = k
break
filename = 'data/交警支队名单221010.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
filename = 'data/交警支队手机号码221010.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')
In [ ]:
import json
import csv
filename = 'data/交警支队小鹅通信息221018.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/交警支队分组情况.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
phone = line[9]
group = line[1]
if phone in dict1.keys():
dict1[phone]['group'] = group
filename = 'data/交警支队小鹅通信息221018.json'
with open(filename,'w') as fl:
json.dump(dict1, fl,ensure_ascii=False) In [ ]:
import json
filename = 'data/交警支队名单221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
for k, v in dict1.items():
if 'phone' in v.keys():
dict2.setdefault(v['phone'], {})
dict2[v['phone']]['name'] = v['name']
dict2[v['phone']]['sex'] = v['sex']
dict2[v['phone']]['unit'] = v['unit']
dict2[v['phone']]['birth'] = v['birth']
#print(dict2)
list1 = dict2.keys()
filename = 'data/小鹅通人员信息221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k, v in dict1.items():
phone = v['phone']
if phone in list1:
dict2[phone]['nick'] = v['nick']
dict2[phone]['user'] = v['name']
dict2[phone]['id'] = k
filename = 'data/交警支队小鹅通信息221010.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok') In [ ]:
import openpyxl
import json
filename = 'data/交警支队小鹅通信息221018.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
wb = openpyxl.load_workbook('data/新增人员表221018.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
for n in range(2, sheet.max_row+1):
if sheet.cell(n,1).value is None:
break
else:
phone = sheet.cell(n, 5).value
if phone in dict2.keys():
dict2[phone]['id'] = sheet.cell(n, 1).value
dict2[phone]['nick'] = sheet.cell(n, 3).value
dict2[phone]['user'] = sheet.cell(n, 2).value
print(sheet.cell(n, 1).value,sheet.cell(n, 3).value,sheet.cell(n, 2).value,phone)
#with open(filename, 'w') as fl:
# json.dump(dict2, fl, ensure_ascii=False)
#print('ok')In [ ]:
import openpyxl
import json
import os
import glob
import csv
import re
filename = 'data/交警支队小鹅通信息221018.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
for k, v in dict1.items():
if 'id' in v.keys():
dict2[v['id']] = [v['name'],v['unit'],k,v['nick'],v['group']]
dict3 = {}
fi_path = 'data/交警支队/打卡/'
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
for fn in fl:
with open(fn,'r',newline='') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
group = re.findall(r'百日筑基-(.+)》',fn)[0]
header = next(fl1)
for line in fl1:
id = line[0]
num = line[10]
#print(id,num)
if id in dict2.keys() and dict2[id][4] == group:
dict3.setdefault(id,{})
dict3[id]['name'] = dict2[id][0]
dict3[id]['phone'] = dict2[id][2]
dict3[id]['unit'] = dict2[id][1]
dict3[id]['nick'] = dict2[id][3]
dict3[id]['dk'] = num
fi_path = 'data/交警支队/时长/'
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
for fn in fl:
with open(fn,'r',newline='',encoding='gb18030') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
group = re.findall(r'《(.+)》',fn)[0]
#header = next(fl1)
i = 0
for line in fl1:
#line = re.sub('[\r\n\f ]{1,}', '', line)
if i> 1:
list1.append(line)
id = line[0]
if id in dict2.keys() and dict2[id][4] == group:
dict3.setdefault(id,{})
dict3[id]['name'] = dict2[id][0]
dict3[id]['phone'] = dict2[id][2]
dict3[id]['unit'] = dict2[id][1]
dict3[id]['nick'] = dict2[id][3]
dict3[id]['sc'] = line[6]
i +=1
list1 = []
for k, v in dict3.items():
list2 = []
if 'dk' in v.keys():
dk = v['dk']
else:
dk = 0
if 'sc' in v.keys():
sc = v['sc']
else:
sc = ''
list2 = [k,v['name'],v['phone'],v['unit'],dk,sc]
list1.append(list2)
title = ['昵称','姓名','手机号','部门','打卡次数','累计学习时长']
filename = 'data/交警支队学习情况表221212.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename) In [ ]:
import openpyxl
import json
import os
import glob
import csv
import re
filename = 'data/交警支队小鹅通信息221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
for k, v in dict1.items():
if 'id' in v.keys():
dict2[v['id']] = [v['name'],v['unit'],k,v['nick'],v['group']]
dict3 = {}
fi_path = 'data/交警支队/打卡/'
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
for fn in fl:
with open(fn,'r',newline='') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
group = re.findall(r'百日筑基-(.+)》',fn)[0]
header = next(fl1)
for line in fl1:
#line = re.sub('[\r\n\f ]{1,}', '', line)
id = line[0]
num = line[10]
#print(id,num)
if id not in dict2.keys():
dict3.setdefault(id,{})
dict3[id]['name'] = line[4]
dict3[id]['phone'] = line[5]
dict3[id]['nick'] = line[1]
fi_path = 'data/交警支队/时长/'
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
for fn in fl:
with open(fn,'r',newline='',encoding='gb18030') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
group = re.findall(r'《(.+)》',fn)[0]
#header = next(fl1)
i = 0
for line in fl1:
#line = re.sub('[\r\n\f ]{1,}', '', line)
if i> 1:
id = line[0]
if id not in dict2.keys():
dict3.setdefault(id,{})
dict3[id]['name'] = line[10]
dict3[id]['phone'] = line[11]
dict3[id]['nick'] = line[1]
i +=1
#print(dict3)
for k, v in dict3.items():
phone = re.sub('[\r\n\f\t ]{1,}', '',v['phone'])
if phone in dict1.keys():
dict1[phone]['id'] = k
dict1[phone]['nick'] = v['nick']
dict1[phone]['user'] = v['name']
else:
list1.append([k,v['name'],v['nick'],phone])
filename = 'data/交警支队小鹅通信息221018.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
title = ['id','姓名','昵称','手机号']
filename = 'data/新增人员表221018.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)
print('ok')In [ ]:
import openpyxl
import json
import os
import glob
import csv
import re
filename = 'data/交警支队小鹅通信息221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
for k, v in dict1.items():
if 'id' in v.keys():
dict2[v['id']] = [v['name'],v['unit'],k,v['nick'],v['group']]
dict3 = {}
fi_path = 'data/交警支队/打卡/'
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
for fn in fl:
with open(fn,'r',newline='') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
group = re.findall(r'百日筑基-(.+)》',fn)[0]
header = next(fl1)
for line in fl1:
#line = re.sub('[\r\n\f ]{1,}', '', line)
id = line[0]
num = line[10]
#print(id,num)
if id not in dict2.keys():
dict3.setdefault(id,{})
dict3[id]['name'] = line[4]
dict3[id]['phone'] = line[5]
dict3[id]['nick'] = line[1]
fi_path = 'data/交警支队/时长/'
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
for fn in fl:
with open(fn,'r',newline='',encoding='gb18030') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
group = re.findall(r'《(.+)》',fn)[0]
#header = next(fl1)
i = 0
for line in fl1:
#line = re.sub('[\r\n\f ]{1,}', '', line)
if i> 1:
id = line[0]
if id not in dict2.keys():
dict3.setdefault(id,{})
dict3[id]['name'] = line[10]
dict3[id]['phone'] = line[11]
dict3[id]['nick'] = line[1]
i +=1
i = 1
#print(dict3)
for k, v in dict3.items():
phone = re.sub('[\r\n\f\t ]{1,}', '',v['phone'])
if phone not in dict1.keys():
#dict1[phone]['id'] = k
#dict1[phone]['nick'] = v['nick']
#dict1[phone]['user'] = v['name']
print(i,k,v['nick'], v['name'],phone)
i+=1
In [ ]:
import json
filename = 'data/交警支队名单221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k, v in dict1.items():
if 'phone' not in v.keys():
print(v['name'],v['unit'])In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/新部门排序-淄博交警支队人员名单 _56473.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict2 = {}
data1 =list(sheet.values)
del data1[0]
for item in data1:
phone = item[4]
dict2[phone] = [item[1],item[0]]
#print(dict2)
dict3 = {}
filename = 'data/交警支队小鹅通信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k, v in dict1.items():
if k not in dict2.keys():
print(k,dict1[k]['name'])
#with open(filename, 'w') as fl:
# json.dump(person, fl, ensure_ascii=False)
#print('ok')In [ ]:
import json
import csv
filename = 'data/交警支队手机号码221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/交警支队分组情况.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
phone = line[9]
group = line[1]
if phone not in dict1.keys():
print(line[2],line[9],line[3])
In [ ]:
import json
import csv
filename = 'data/交警支队手机号码221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/小鹅通人员信息221010.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k, v in dict2.items():
phone = v['phone']
if phone not in dict1.keys():
print(k,v['nick'],v['name'],phone)
In [ ]:
import json
import os
import glob
import csv
import re
fi_path = 'data/交警支队/打卡/'
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
dict1 = {}
for fn in fl:
with open(fn,'r',newline='') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
zb = fn.split('-')[3]
#header = next(fl1)
i = 0
for line in fl1:
#line = re.sub('[\r\n\f ]{1,}', '', line)
if i> 1:
m_id = line[0]
dict1.setdefault(m_id,[])
dict1[m_id].append(zb)
#list1.append(line)
i +=1
filename = 'data/交警支队小鹅通信息221018.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
dict3 = {}
for k ,v in dict2.items():
if 'id' in v.keys():
dict3[v['id']] = [k,v['name'],v['unit'],v['nick']]
for k, v in dict1.items():
if k in dict3.keys():
if len(v)>1:
print(dict3[k][1],dict3[k][2],dict3[k][0],v)
In [ ]:
import json
filename = 'data/交警支队名单221010.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
i = 0
for k, v in dict1.items():
if v['unit'] == '支高新区大队':
dict1[k]['unit'] = '高新区大队'
i +=1
with open(filename,'w') as fl:
json.dump(dict1, fl,ensure_ascii=False)
print(f'共有{i}条记录被修改')In [ ]:
import openpyxl
import json
import csv
wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
cjry = set()
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
phone = sheet.cell(n, 5).value
person.setdefault(phone, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
xb = str(sheet.cell(n, 3).value)
if xb == '1':
sex = '男'
elif xb =='2':
sex = '女'
dict1['sex'] = sex
dict1['unit'] = sheet.cell(n, 1).value
person[phone] = dict1
list1 = []
filename = 'data/Survey_20230424-tcm5.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
#line = re.sub('[\r\n\f ]{1,}', '', line)
cjry.add(line[2])
print(len(cjry))
list2 = []
for k, v in person.items():
if k not in cjry:
list2.append([k,person[k]['name'],person[k]['unit']])
filename = 'data/交警支队未参加中医评估人员(20230424).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list2:
sheet.append(row)
wb.save(filename)In [ ]:
import openpyxl
import json
import csv
wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
cjry = set()
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:gangx
break
else:
phone = sheet.cell(n, 5).value
person.setdefault(phone, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
xb = str(sheet.cell(n, 3).value)
if xb == '1':
sex = '男'
elif xb =='2':
sex = '女'
dict1['sex'] = sex
dict1['unit'] = sheet.cell(n, 1).value
person[phone] = dict1
list1 = []
filename = 'data/Survey_20230424-jj.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
#line = re.sub('[\r\n\f ]{1,}', '', line)
cjry.add(line[2])
print(len(cjry))
list2 = []
for item in cjry:
if str(item) not in person.keys():
list2.append(['','',item])
filename = 'data/交警支队缺失信息人员(20230424).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list2:
sheet.append(row)
wb.save(filename)
In [ ]:
import openpyxl
import json
import glob,os,shutil
from pathlib2 import Path
import csv
wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
depart = []
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
phone = sheet.cell(n, 5).value
person.setdefault(phone, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
xb = str(sheet.cell(n, 3).value)
if xb == '1':
sex = '男'
elif xb =='2':
sex = '女'
dict1['sex'] = sex
dict1['unit'] = sheet.cell(n, 1).value
person[phone] = dict1
list1 = []
dict1 = {}
old = []
fi_path = 'file/132/20230425'
fl=glob.glob(f'{fi_path}/*.pdf')
print(len(fl))
for fn in fl:
phone = Path(fn).stem
if phone in person.keys():
name = person[phone]['name']
unit = person[phone]['unit']
else:
name = ''
unit ='未明确部门'
if unit not in depart:
depart.append(unit)
dict1[phone] = {'name':name,'unit':unit}
print(depart)
m_path = 'file/132/new'
for pn in depart:
if not os.path.exists(m_path + '/' + pn):
os.mkdir(m_path + '/' + pn)
fl=os.listdir(fi_path)
for fn in fl:
if os.path.isfile(fi_path + '/' + fn):
ofn = int(fn.split('.')[0])
old.append(ofn)
old.sort()
for n in old:
o_name = f'{fi_path}/{n}.pdf'
unit = dict1[str(n)]['unit']
n_name = f'{m_path}/{unit}/{str(n)}.pdf'
#print(o_name,n_name)
if not os.path.exists(n_name):
shutil.copyfile(o_name,n_name)
print(n_name)In [44]:
import openpyxl
import json
import glob,os,shutil
from pathlib2 import Path
import csv
wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
depart = []
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
phone = sheet.cell(n, 5).value
person.setdefault(phone, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
xb = str(sheet.cell(n, 3).value)
if xb == '1':
sex = '男'
elif xb =='2':
sex = '女'
dict1['sex'] = sex
dict1['unit'] = sheet.cell(n, 1).value
person[phone] = dict1
list1 = []
dict1 = {}
old = []
fi_path = 'file/132/20230425'
fl=glob.glob(f'{fi_path}/*.pdf')
print(len(fl))
for fn in fl:
phone = Path(fn).stem
if phone in person.keys():
name = person[phone]['name']
unit = person[phone]['unit']
else:
name = ''
unit ='未明确部门'
if unit not in depart:
depart.append(unit)
dict1[phone] = {'name':name,'unit':unit}
print(depart)
m_path = 'file/132/new'
for pn in depart:
if not os.path.exists(m_path + '/' + pn):
os.mkdir(m_path + '/' + pn)
fl=os.listdir(fi_path)
for fn in fl:
if os.path.isfile(fi_path + '/' + fn):
ofn = int(fn.split('.')[0])
old.append(ofn)
old.sort()
for n in old:
o_name = f'{fi_path}/{n}.pdf'
unit = dict1[str(n)]['unit']
n_name = f'{m_path}/{unit}/{str(n)}.pdf'
list1.append([unit,n])
filename = 'data/淄博交警报告打印明细表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
title = ['部门','手机号码']
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)452 ['博山大队', '桓台大队', '未明确部门', '支队', '淄川大队', '文昌湖大队', '支队车管所', '高青大队', '张店大队', '设施大队', '周村大队', '高新区大队', '支队外调人员', '沂源大队', '退休人员', '临淄大队']
In [51]:
import openpyxl
import json
import glob,os,shutil
from pathlib2 import Path
import csv
wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
depart = []
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
phone = sheet.cell(n, 5).value
person.setdefault(phone, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
xb = str(sheet.cell(n, 3).value)
if xb == '1':
sex = '男'
elif xb =='2':
sex = '女'
dict1['sex'] = sex
dict1['unit'] = sheet.cell(n, 1).value
person[phone] = dict1
list1 = []
dict1 = {}
old = []
fi_path = 'file/132/20230425'
fl=glob.glob(f'{fi_path}/*.pdf')
print(len(fl))
for fn in fl:
phone = Path(fn).stem
if phone in person.keys():
name = person[phone]['name']
unit = person[phone]['unit']
sex = person[phone]['sex']
else:
name = ''
unit ='未明确部门'
sex = ''
if unit not in depart:
depart.append(unit)
dict1[phone] = {'name':name,'unit':unit,'sex':sex}
filename = 'data/淄博交警参加测评人员.json'
with open(filename,'w') as fl:
json.dump(dict1, fl,ensure_ascii=False) 452
In [52]:
import openpyxl
import json
import csv
filename = 'data/淄博交警参加测评人员.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
cjry = set()
filename = 'data/Survey_20230424-psy3.csv'
list2 = []
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
#line = re.sub('[\r\n\f ]{1,}', '', line)
phone = str(line[2])
result = json.loads(line[5])
if phone in dict1.keys():
list1 = []
list1.append(phone)
list1.append(dict1[phone]['name'])
list1.append(dict1[phone]['sex'])
list1.append(dict1[phone]['unit'])
#print(k,v['phone'],type(result))
for k1, v1 in result.items():
list1.append(v1)
list2.append(list1)
filename = 'data/交警心理评估明细表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list2:
sheet.append(row)
wb.save(filename)In [53]:
import openpyxl
import json
import csv
filename = 'data/淄博交警参加测评人员.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
cjry = set()
filename = 'data/Survey_20230424-tcm5.csv'
list2 = []
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
#line = re.sub('[\r\n\f ]{1,}', '', line)
phone = str(line[2])
result = json.loads(line[5])
if phone in dict1.keys():
list1 = []
list1.append(phone)
list1.append(dict1[phone]['name'])
list1.append(dict1[phone]['sex'])
list1.append(dict1[phone]['unit'])
#print(k,v['phone'],type(result))
for k1, v1 in result.items():
list1.append(v1)
list2.append(list1)
filename = 'data/交警中医评估明细表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list2:
sheet.append(row)
wb.save(filename)In [ ]: