def wenjuanxing(filepath='.\\data', headlen=6):
    '问卷星数据导入和编码\n    输入：\n    filepath:\n        列表, filepath[0]: (23_22_0.xls)为按文本数据路径，filepath[1]: (23_22_2.xls)为按序号文本\n        文件夹路径，函数会自动在文件夹下搜寻相关数据，优先为\\d+_\\d+_0.xls和\\d+_\\d+_2.xls\n    headlen: 问卷星数据基础信息的列数\n    输出：\n    (data,code):\n        data为按序号的数据，题目都替换成了Q_n\n        code为数据编码，可利用函数to_code()导出为json格式或者Excel格式数据\n    '
    if isinstance(filepath, list):
        filename1 = filepath[0]
        filename2 = filepath[1]
    elif os.path.isdir(filepath):
        filelist = os.listdir(filepath)
        n1 = n2 = 0
        for f in filelist:
            s1 = re.findall('\\d+_\\d+_0.xls', f)
            s2 = re.findall('\\d+_\\d+_2.xls', f)
            if s1:
                filename1 = s1[0]
                n1 += 1
            if s2:
                filename2 = s2[0]
                n2 += 1
        if ((n1 + n2) == 0):
            print(u'在文件夹下没有找到问卷星按序号和按文本数据，请检查目录或者工作目录.')
            return
        elif ((n1 + n2) > 2):
            print(u'存在多组问卷星数据，请检查.')
            return
        filename1 = os.path.join(filepath, filename1)
        filename2 = os.path.join(filepath, filename2)
    else:
        print('can not dection the filepath!')
    d1 = pd.read_excel(filename1)
    d2 = pd.read_excel(filename2)
    d2.replace({(- 2): np.nan, (- 3): np.nan}, inplace=True)
    code = {}
    '\n    遍历一遍按文本数据，获取题号和每个题目的类型\n    '
    for name in d1.columns[headlen:]:
        tmp = re.findall(u'^(\\d{1,3})[、：:]', name)
        if tmp:
            new_name = ('Q' + tmp[0])
            current_name = ('Q' + tmp[0])
            code[new_name] = {}
            content = re.findall(u'\\d{1,3}[、：:](.*)', name)
            code[new_name]['content'] = content[0]
            d1.rename(columns={name: new_name}, inplace=True)
            code[new_name]['qlist'] = []
            code[new_name]['code'] = {}
            code[new_name]['qtype'] = ''
            code[new_name]['name'] = ''
            qcontent = str(list(d1[new_name]))
            if (('〖' in qcontent) and ('〗' in qcontent)):
                code[new_name]['qlist_open'] = []
            if ('┋' in qcontent):
                code[new_name]['qtype'] = u'多选题'
            elif ('→' in qcontent):
                code[new_name]['qtype'] = u'排序题'
        else:
            tmp2 = re.findall(u'^第(\\d{1,3})题\\(.*?\\)', name)
            if tmp2:
                new_name = ('Q' + tmp2[0])
            else:
                pass
            if (new_name not in code.keys()):
                j = 1
                current_name = new_name
                new_name = (new_name + ('_R%s' % j))
                code[current_name] = {}
                code[current_name]['content'] = (current_name + '(问卷星数据中未找到题目具体内容)')
                code[current_name]['qlist'] = []
                code[current_name]['code'] = {}
                code[current_name]['code_r'] = {}
                code[current_name]['qtype'] = u'矩阵单选题'
                code[current_name]['name'] = ''
                d1.rename(columns={name: new_name}, inplace=True)
            else:
                j += 1
                new_name = (new_name + ('_R%s' % j))
                d1.rename(columns={name: new_name}, inplace=True)
    d2qlist = d2.columns[6:].tolist()
    for name in d2qlist:
        tmp1 = re.findall(u'^(\\d{1,3})[、：:]', name)
        tmp2 = re.findall(u'^第(.*?)题', name)
        if tmp1:
            current_name = ('Q' + tmp1[0])
            d2.rename(columns={name: current_name}, inplace=True)
            code[current_name]['qlist'].append(current_name)
            ind = d2[current_name].copy()
            ind = ind.notnull()
            c1 = d1.loc[(ind, current_name)].unique()
            c2 = d2.loc[(ind, current_name)].unique()
            if ((c2.dtype == object) or ((list(c1) == list(c2)) and (len(c2) >= min(15, len(d2[ind])))) or (len(c2) > 50)):
                code[current_name]['qtype'] = u'填空题'
            else:
                code[current_name]['qtype'] = u'单选题'
                if ('qlist_open' in code[current_name].keys()):
                    tmp = d1[current_name].map((lambda x: (re.findall('〖(.*?)〗', x)[0] if re.findall('〖(.*?)〗', x) else '')))
                    ind_open = np.argwhere((d2.columns.values == current_name)).tolist()[0][0]
                    d2.insert((ind_open + 1), (current_name + '_open'), tmp)
                    d1[current_name] = d1[current_name].map((lambda x: re.sub('〖.*?〗', '', x)))
                    code[current_name]['qlist_open'] = [(current_name + '_open')]
                code[current_name]['code'] = dict(zip(d2.loc[(ind, current_name)], d1.loc[(ind, current_name)]))
        elif tmp2:
            name0 = ('Q' + tmp2[0])
            if (name0 != current_name):
                j = 1
                current_name = name0
                c2 = list(d2[name].unique())
                if (code[current_name]['qtype'] == u'矩阵单选题'):
                    name1 = (('Q' + tmp2[0]) + ('_R%s' % j))
                    c1 = list(d1[name1].unique())
                    code[current_name]['code'] = dict(zip(c2, c1))
                else:
                    name1 = (('Q' + tmp2[0]) + ('_A%s' % j))
            else:
                j += 1
                c2 = list(d2[name].unique())
                if (code[current_name]['qtype'] == u'矩阵单选题'):
                    name1 = (('Q' + tmp2[0]) + ('_R%s' % j))
                    c1 = list(d1[name1].unique())
                    old_dict = code[current_name]['code'].copy()
                    new_dict = dict(zip(c2, c1))
                    old_dict.update(new_dict)
                    code[current_name]['code'] = old_dict.copy()
                else:
                    name1 = (('Q' + tmp2[0]) + ('_A%s' % j))
            code[current_name]['qlist'].append(name1)
            d2.rename(columns={name: name1}, inplace=True)
            tmp3 = re.findall(u'第.*?题\\((.*)\\)', name)[0]
            if (code[current_name]['qtype'] == u'矩阵单选题'):
                code[current_name]['code_r'][name1] = tmp3
            else:
                code[current_name]['code'][name1] = tmp3
            if (code[current_name]['qtype'] == u'多选题'):
                openq = (tmp3 + '〖.*?〗')
                openq = re.sub('\\)', '\\)', openq)
                openq = re.sub('\\(', '\\(', openq)
                openq = re.compile(openq)
                qcontent = str(list(d1[current_name]))
                if re.findall(openq, qcontent):
                    tmp = d1[current_name].map((lambda x: (re.findall(openq, x)[0] if re.findall(openq, x) else '')))
                    ind = np.argwhere((d2.columns.values == name1)).tolist()[0][0]
                    d2.insert((ind + 1), (name1 + '_open'), tmp)
                    code[current_name]['qlist_open'].append((name1 + '_open'))
        keys = list(code[current_name]['code'].keys())
        for key in keys:
            if (('%s' % key) == 'nan'):
                del code[current_name]['code'][key]
    for k in code.keys():
        content = code[k]['content']
        qtype = code[k]['qtype']
        if (('code' in code[k]) and (code[k]['code'] != {})):
            tmp1 = code[k]['code'].keys()
            tmp2 = code[k]['code'].values()
            tmp3 = [(len(re.findall('\\d+', ('%s' % v))) > 0) for v in tmp2]
            tmp4 = [(len(re.findall('-|~', ('%s' % v))) > 0) for v in tmp2]
            if ((np.array(tmp3).sum() >= (len(tmp2) - 2)) or (np.array(tmp4).sum() >= ((len(tmp2) * 0.8) - 1e-17))):
                try:
                    tmp_key = sorted(code[k]['code'], key=(lambda c: float(re.findall('[\\d\\.]+', ('%s' % c))[(- 1)])))
                except:
                    tmp_key = list(tmp1)
                code_order = [code[k]['code'][v] for v in tmp_key]
                code[k]['code_order'] = code_order
            if (qtype == '矩阵单选题'):
                tmp3 = [int(re.findall('\\d+', ('%s' % v))[0]) for v in tmp2 if re.findall('\\d+', ('%s' % v))]
                if ((set(tmp3) <= set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) and (len(tmp3) == len(tmp2))):
                    code[k]['weight'] = dict(zip(tmp1, tmp3))
                    continue
            if (('性别' in content) and ('男' in tmp2) and ('女' in tmp2)):
                code[k]['name'] = '性别'
            if (('gender' in content.lower()) and ('Male' in tmp2) and ('Female' in tmp2)):
                code[k]['name'] = '性别'
            if ((('年龄' in content) or ('age' in content.lower())) and (np.array(tmp3).sum() >= (len(tmp2) - 1))):
                code[k]['name'] = '年龄'
            if (('满意度' in content) and ('整体' in content)):
                tmp3 = [int(re.findall('\\d+', ('%s' % v))[0]) for v in tmp2 if re.findall('\\d+', ('%s' % v))]
                if (set(tmp3) <= set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])):
                    code[k]['name'] = '满意度'
                    if (len(tmp3) == len(tmp2)):
                        code[k]['weight'] = dict(zip(tmp1, tmp3))
            if (('意愿' in content) and ('推荐' in content)):
                tmp3 = [int(re.findall('\\d+', ('%s' % v))[0]) for v in tmp2 if re.findall('\\d+', ('%s' % v))]
                if (set(tmp3) <= set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])):
                    code[k]['name'] = 'NPS'
                    if (len(tmp3) == len(tmp2)):
                        weight = pd.Series(dict(zip(tmp1, tmp3)))
                        weight = weight.replace(dict(zip([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [(- 100), (- 100), (- 100), (- 100), (- 100), (- 100), (- 100), 0, 0, 100, 100])))
                        code[k]['weight'] = weight.to_dict()
    try:
        d2[u'所用时间'] = d2[u'所用时间'].map((lambda s: int(s[:(- 1)])))
    except:
        pass
    return (d2, code)
问卷星数据导入和编码
输入：
filepath:
    列表, filepath[0]: (23_22_0.xls)为按文本数据路径，filepath[1]: (23_22_2.xls)为按序号文本
    文件夹路径，函数会自动在文件夹下搜寻相关数据，优先为\d+_\d+_0.xls和\d+_\d+_2.xls
headlen: 问卷星数据基础信息的列数
输出：
(data,code):
    data为按序号的数据，题目都替换成了Q_n
    code为数据编码，可利用函数to_code()导出为json格式或者Excel格式数据
def wenjuanxing(filepath='.\\data', headlen=6):
    '问卷星数据导入和编码\n    输入：\n    filepath:\n        列表, filepath[0]: (23_22_0.xls)为按文本数据路径，filepath[1]: (23_22_2.xls)为按序号文本\n        文件夹路径，函数会自动在文件夹下搜寻相关数据，优先为\\d+_\\d+_0.xls和\\d+_\\d+_2.xls\n    headlen: 问卷星数据基础信息的列数\n    输出：\n    (data,code):\n        data为按序号的数据，题目都替换成了Q_n\n        code为数据编码，可利用函数to_code()导出为json格式或者Excel格式数据\n    '
    if isinstance(filepath, list):
        filename1 = filepath[0]
        filename2 = filepath[1]
    elif os.path.isdir(filepath):
        filelist = os.listdir(filepath)
        n1 = n2 = 0
        for f in filelist:
            s1 = re.findall('\\d+_\\d+_0.xls', f)
            s2 = re.findall('\\d+_\\d+_2.xls', f)
            if s1:
                filename1 = s1[0]
                n1 += 1
            if s2:
                filename2 = s2[0]
                n2 += 1
        if ((n1 + n2) == 0):
            print(u'在文件夹下没有找到问卷星按序号和按文本数据，请检查目录或者工作目录.')
            return
        elif ((n1 + n2) > 2):
            print(u'存在多组问卷星数据，请检查.')
            return
        filename1 = os.path.join(filepath, filename1)
        filename2 = os.path.join(filepath, filename2)
    else:
        print('can not dection the filepath!')
    d1 = pd.read_excel(filename1)
    d2 = pd.read_excel(filename2)
    d2.replace({(- 2): np.nan, (- 3): np.nan}, inplace=True)
    code = {}
    '\n    遍历一遍按文本数据，获取题号和每个题目的类型\n    '
    for name in d1.columns[headlen:]:
        tmp = re.findall(u'^(\\d{1,3})[、：:]', name)
        if tmp:
            new_name = ('Q' + tmp[0])
            current_name = ('Q' + tmp[0])
            code[new_name] = {}
            content = re.findall(u'\\d{1,3}[、：:](.*)', name)
            code[new_name]['content'] = content[0]
            d1.rename(columns={name: new_name}, inplace=True)
            code[new_name]['qlist'] = []
            code[new_name]['code'] = {}
            code[new_name]['qtype'] = 
            code[new_name]['name'] = 
            qcontent = str(list(d1[new_name]))
            if (('〖' in qcontent) and ('〗' in qcontent)):
                code[new_name]['qlist_open'] = []
            if ('┋' in qcontent):
                code[new_name]['qtype'] = u'多选题'
            elif ('→' in qcontent):
                code[new_name]['qtype'] = u'排序题'
        else:
            tmp2 = re.findall(u'^第(\\d{1,3})题\\(.*?\\)', name)
            if tmp2:
                new_name = ('Q' + tmp2[0])
            else:
                pass
            if (new_name not in code.keys()):
                j = 1
                current_name = new_name
                new_name = (new_name + ('_R%s' % j))
                code[current_name] = {}
                code[current_name]['content'] = (current_name + '(问卷星数据中未找到题目具体内容)')
                code[current_name]['qlist'] = []
                code[current_name]['code'] = {}
                code[current_name]['code_r'] = {}
                code[current_name]['qtype'] = u'矩阵单选题'
                code[current_name]['name'] = 
                d1.rename(columns={name: new_name}, inplace=True)
            else:
                j += 1
                new_name = (new_name + ('_R%s' % j))
                d1.rename(columns={name: new_name}, inplace=True)
    d2qlist = d2.columns[6:].tolist()
    for name in d2qlist:
        tmp1 = re.findall(u'^(\\d{1,3})[、：:]', name)
        tmp2 = re.findall(u'^第(.*?)题', name)
        if tmp1:
            current_name = ('Q' + tmp1[0])
            d2.rename(columns={name: current_name}, inplace=True)
            code[current_name]['qlist'].append(current_name)
            ind = d2[current_name].copy()
            ind = ind.notnull()
            c1 = d1.loc[(ind, current_name)].unique()
            c2 = d2.loc[(ind, current_name)].unique()
            if ((c2.dtype == object) or ((list(c1) == list(c2)) and (len(c2) >= min(15, len(d2[ind])))) or (len(c2) > 50)):
                code[current_name]['qtype'] = u'填空题'
            else:
                code[current_name]['qtype'] = u'单选题'
                if ('qlist_open' in code[current_name].keys()):
                    tmp = d1[current_name].map((lambda x: (re.findall('〖(.*?)〗', x)[0] if re.findall('〖(.*?)〗', x) else )))
                    ind_open = np.argwhere((d2.columns.values == current_name)).tolist()[0][0]
                    d2.insert((ind_open + 1), (current_name + '_open'), tmp)
                    d1[current_name] = d1[current_name].map((lambda x: re.sub('〖.*?〗', , x)))
                    code[current_name]['qlist_open'] = [(current_name + '_open')]
                code[current_name]['code'] = dict(zip(d2.loc[(ind, current_name)], d1.loc[(ind, current_name)]))
        elif tmp2:
            name0 = ('Q' + tmp2[0])
            if (name0 != current_name):
                j = 1
                current_name = name0
                c2 = list(d2[name].unique())
                if (code[current_name]['qtype'] == u'矩阵单选题'):
                    name1 = (('Q' + tmp2[0]) + ('_R%s' % j))
                    c1 = list(d1[name1].unique())
                    code[current_name]['code'] = dict(zip(c2, c1))
                else:
                    name1 = (('Q' + tmp2[0]) + ('_A%s' % j))
            else:
                j += 1
                c2 = list(d2[name].unique())
                if (code[current_name]['qtype'] == u'矩阵单选题'):
                    name1 = (('Q' + tmp2[0]) + ('_R%s' % j))
                    c1 = list(d1[name1].unique())
                    old_dict = code[current_name]['code'].copy()
                    new_dict = dict(zip(c2, c1))
                    old_dict.update(new_dict)
                    code[current_name]['code'] = old_dict.copy()
                else:
                    name1 = (('Q' + tmp2[0]) + ('_A%s' % j))
            code[current_name]['qlist'].append(name1)
            d2.rename(columns={name: name1}, inplace=True)
            tmp3 = re.findall(u'第.*?题\\((.*)\\)', name)[0]
            if (code[current_name]['qtype'] == u'矩阵单选题'):
                code[current_name]['code_r'][name1] = tmp3
            else:
                code[current_name]['code'][name1] = tmp3
            if (code[current_name]['qtype'] == u'多选题'):
                openq = (tmp3 + '〖.*?〗')
                openq = re.sub('\\)', '\\)', openq)
                openq = re.sub('\\(', '\\(', openq)
                openq = re.compile(openq)
                qcontent = str(list(d1[current_name]))
                if re.findall(openq, qcontent):
                    tmp = d1[current_name].map((lambda x: (re.findall(openq, x)[0] if re.findall(openq, x) else )))
                    ind = np.argwhere((d2.columns.values == name1)).tolist()[0][0]
                    d2.insert((ind + 1), (name1 + '_open'), tmp)
                    code[current_name]['qlist_open'].append((name1 + '_open'))
        keys = list(code[current_name]['code'].keys())
        for key in keys:
            if (('%s' % key) == 'nan'):
                del code[current_name]['code'][key]
    for k in code.keys():
        content = code[k]['content']
        qtype = code[k]['qtype']
        if (('code' in code[k]) and (code[k]['code'] != {})):
            tmp1 = code[k]['code'].keys()
            tmp2 = code[k]['code'].values()
            tmp3 = [(len(re.findall('\\d+', ('%s' % v))) > 0) for v in tmp2]
            tmp4 = [(len(re.findall('-|~', ('%s' % v))) > 0) for v in tmp2]
            if ((np.array(tmp3).sum() >= (len(tmp2) - 2)) or (np.array(tmp4).sum() >= ((len(tmp2) * 0.8) - 1e-17))):
                try:
                    tmp_key = sorted(code[k]['code'], key=(lambda c: float(re.findall('[\\d\\.]+', ('%s' % c))[(- 1)])))
                except:
                    tmp_key = list(tmp1)
                code_order = [code[k]['code'][v] for v in tmp_key]
                code[k]['code_order'] = code_order
            if (qtype == '矩阵单选题'):
                tmp3 = [int(re.findall('\\d+', ('%s' % v))[0]) for v in tmp2 if re.findall('\\d+', ('%s' % v))]
                if ((set(tmp3) <= set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) and (len(tmp3) == len(tmp2))):
                    code[k]['weight'] = dict(zip(tmp1, tmp3))
                    continue
            if (('性别' in content) and ('男' in tmp2) and ('女' in tmp2)):
                code[k]['name'] = '性别'
            if (('gender' in content.lower()) and ('Male' in tmp2) and ('Female' in tmp2)):
                code[k]['name'] = '性别'
            if ((('年龄' in content) or ('age' in content.lower())) and (np.array(tmp3).sum() >= (len(tmp2) - 1))):
                code[k]['name'] = '年龄'
            if (('满意度' in content) and ('整体' in content)):
                tmp3 = [int(re.findall('\\d+', ('%s' % v))[0]) for v in tmp2 if re.findall('\\d+', ('%s' % v))]
                if (set(tmp3) <= set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])):
                    code[k]['name'] = '满意度'
                    if (len(tmp3) == len(tmp2)):
                        code[k]['weight'] = dict(zip(tmp1, tmp3))
            if (('意愿' in content) and ('推荐' in content)):
                tmp3 = [int(re.findall('\\d+', ('%s' % v))[0]) for v in tmp2 if re.findall('\\d+', ('%s' % v))]
                if (set(tmp3) <= set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])):
                    code[k]['name'] = 'NPS'
                    if (len(tmp3) == len(tmp2)):
                        weight = pd.Series(dict(zip(tmp1, tmp3)))
                        weight = weight.replace(dict(zip([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [(- 100), (- 100), (- 100), (- 100), (- 100), (- 100), (- 100), 0, 0, 100, 100])))
                        code[k]['weight'] = weight.to_dict()
    try:
        d2[u'所用时间'] = d2[u'所用时间'].map((lambda s: int(s[:(- 1)])))
    except:
        pass
    return (d2, code)