1.excel文件
https://download.csdn.net/download/qq_42972591/74125316
import pandas as pd
import re
import json
df=pd.read_excel('文化题库.xlsx',sheet_name ='Sheet1')
k='[A-Z]'
dic={
}
#清空base.txt
with open('base.txt','w') as f:
pass
#表格第一行被读取成columns了,所以从1开始
for i in range(1,161):
line=df.iloc[i]
#line[8]有nan值,需去掉,否则list(line[8])错误
#line[8]!=line[8] 去掉nan
if line[0]=='题型' or line[8]!=line[8]:
continue
answer=list(line[8])#多选选项拆分
answers=''
#匹配选择题
if re.search(k,line[8]):
for it in answer:
pos=ord(it)-63 #'A'的ascii为65,-63对应到表格答案相应的列
answers+=line[pos]+';'
else:
answers=line[8] #判断题直接取答案
line[1]=line[1].replace('\n','')#去掉换行符
key=str(i