def scorpion(data, code, filename='scorpion'):
    '天蝎X计划\n    返回一个excel文件\n    1、索引\n    2、各个题目的频数表\n    3、所有可能的交叉分析\n    '
    if (not os.path.exists('.\\out')):
        os.mkdir('.\\out')
    Writer = pd.ExcelWriter((('.\\out\\' + filename) + '.xlsx'))
    try:
        qqlist = list(sorted(code, key=(lambda c: int(re.findall('\\d+', c)[0]))))
    except:
        qqlist = list(code.keys())
    qIndex = pd.DataFrame(index=qqlist, columns=[u'content', u'qtype', u'SampleSize'])
    qIndex.to_excel(Writer, u'索引')
    Writer_rows = 0
    for qq in qqlist:
        qtitle = code[qq]['content']
        qlist = code[qq]['qlist']
        qtype = code[qq]['qtype']
        if (not (set(qlist) <= set(data.columns))):
            continue
        sample_len_qq = data[code[qq]['qlist']].notnull().T.any().sum()
        qIndex.loc[(qq, u'content')] = qtitle
        qIndex.loc[(qq, u'qtype')] = qtype
        qIndex.loc[(qq, u'SampleSize')] = sample_len_qq
        if (qtype not in [u'单选题', u'多选题', u'排序题', u'矩阵单选题']):
            continue
        try:
            result_t = table(data[qlist], code=code[qq])
        except:
            print(u'脚本处理 {} 时出了一点小问题.....'.format(qq))
            continue
        fop = result_t['fop']
        fo = result_t['fo']
        if ((qtype == u'排序题') and ('TOPN' in result_t)):
            tmp = result_t['TOPN']
            tmp[u'综合'] = fo[u'综合']
            fo = tmp.copy()
            tmp = result_t['TOPN_fo']
            tmp[u'综合'] = fop[u'综合']
            fop = tmp.copy()
        fo_fop = pd.concat([fo, fop], axis=1)
        fo_fop.to_excel(Writer, u'频数表', startrow=Writer_rows, startcol=1, index_label=code[qq]['content'], float_format='%.3f')
        tmp = pd.DataFrame({'name': [qq]})
        tmp.to_excel(Writer, u'频数表', index=False, header=False, startrow=Writer_rows)
        Writer_rows += (len(fo_fop) + 3)
    qIndex.to_excel(Writer, '索引')
    crossAna = pd.DataFrame(columns=['RowVar', 'ColVar', 'SampleSize', 'pvalue', 'significant', 'summary'])
    N = 0
    qqlist = [qq for qq in qqlist if (code[qq]['qtype'] in ['单选题', '多选题', '矩阵单选题', '排序题'])]
    start_time = time.clock()
    N_cal = ((len(qqlist) * (len(qqlist) - 1)) * 0.1)
    for qq1 in qqlist:
        for qq2 in qqlist:
            if ((N >= N_cal) and (N < (N_cal + 1.0))):
                tmp = ((time.clock() - start_time) * 9)
                if (tmp > 60):
                    print('请耐心等待, 预计还需要{:.1f}秒'.format(tmp))
            qtype2 = code[qq2]['qtype']
            if ((qq1 == qq2) or (qtype2 not in [u'单选题', u'多选题'])):
                continue
            data_index = data[code[qq1]['qlist']]
            data_column = data[code[qq2]['qlist']]
            samplesize = data_column.iloc[list(data_index.notnull().T.any()), :].notnull().T.any().sum()
            try:
                fo = qtable(data, code, qq1, qq2)['fo']
            except:
                crossAna.loc[N, :] = [qq1, qq2, samplesize, '', '', '']
                N += 1
                continue
            try:
                cdata = contingency(fo, alpha=0.05)
            except:
                crossAna.loc[N, :] = [qq1, qq2, samplesize, '', '', '']
                N += 1
                continue
            if cdata:
                result = cdata['significant']['result']
                pvalue = cdata['significant']['pvalue']
                summary = cdata['summary']['summary']
            else:
                result = (- 2)
                pvalue = (- 2)
                summary = '没有找到结论'
            summary = '\n'.join(summary.splitlines()[1:])
            if (len(summary) == 0):
                summary = '没有找到结论'
            crossAna.loc[N, :] = [qq1, qq2, samplesize, pvalue, result, summary]
            N += 1
    crossAna.to_excel(Writer, '交叉分析表', index=False)
    Writer.save()
天蝎X计划
返回一个excel文件
1、索引
2、各个题目的频数表
3、所有可能的交叉分析
def scorpion(data, code, filename='scorpion'):
    '天蝎X计划\n    返回一个excel文件\n    1、索引\n    2、各个题目的频数表\n    3、所有可能的交叉分析\n    '
    if (not os.path.exists('.\\out')):
        os.mkdir('.\\out')
    Writer = pd.ExcelWriter((('.\\out\\' + filename) + '.xlsx'))
    try:
        qqlist = list(sorted(code, key=(lambda c: int(re.findall('\\d+', c)[0]))))
    except:
        qqlist = list(code.keys())
    qIndex = pd.DataFrame(index=qqlist, columns=[u'content', u'qtype', u'SampleSize'])
    qIndex.to_excel(Writer, u'索引')
    Writer_rows = 0
    for qq in qqlist:
        qtitle = code[qq]['content']
        qlist = code[qq]['qlist']
        qtype = code[qq]['qtype']
        if (not (set(qlist) <= set(data.columns))):
            continue
        sample_len_qq = data[code[qq]['qlist']].notnull().T.any().sum()
        qIndex.loc[(qq, u'content')] = qtitle
        qIndex.loc[(qq, u'qtype')] = qtype
        qIndex.loc[(qq, u'SampleSize')] = sample_len_qq
        if (qtype not in [u'单选题', u'多选题', u'排序题', u'矩阵单选题']):
            continue
        try:
            result_t = table(data[qlist], code=code[qq])
        except:
            print(u'脚本处理 {} 时出了一点小问题.....'.format(qq))
            continue
        fop = result_t['fop']
        fo = result_t['fo']
        if ((qtype == u'排序题') and ('TOPN' in result_t)):
            tmp = result_t['TOPN']
            tmp[u'综合'] = fo[u'综合']
            fo = tmp.copy()
            tmp = result_t['TOPN_fo']
            tmp[u'综合'] = fop[u'综合']
            fop = tmp.copy()
        fo_fop = pd.concat([fo, fop], axis=1)
        fo_fop.to_excel(Writer, u'频数表', startrow=Writer_rows, startcol=1, index_label=code[qq]['content'], float_format='%.3f')
        tmp = pd.DataFrame({'name': [qq]})
        tmp.to_excel(Writer, u'频数表', index=False, header=False, startrow=Writer_rows)
        Writer_rows += (len(fo_fop) + 3)
    qIndex.to_excel(Writer, '索引')
    crossAna = pd.DataFrame(columns=['RowVar', 'ColVar', 'SampleSize', 'pvalue', 'significant', 'summary'])
    N = 0
    qqlist = [qq for qq in qqlist if (code[qq]['qtype'] in ['单选题', '多选题', '矩阵单选题', '排序题'])]
    start_time = time.clock()
    N_cal = ((len(qqlist) * (len(qqlist) - 1)) * 0.1)
    for qq1 in qqlist:
        for qq2 in qqlist:
            if ((N >= N_cal) and (N < (N_cal + 1.0))):
                tmp = ((time.clock() - start_time) * 9)
                if (tmp > 60):
                    print('请耐心等待, 预计还需要{:.1f}秒'.format(tmp))
            qtype2 = code[qq2]['qtype']
            if ((qq1 == qq2) or (qtype2 not in [u'单选题', u'多选题'])):
                continue
            data_index = data[code[qq1]['qlist']]
            data_column = data[code[qq2]['qlist']]
            samplesize = data_column.iloc[list(data_index.notnull().T.any()), :].notnull().T.any().sum()
            try:
                fo = qtable(data, code, qq1, qq2)['fo']
            except:
                crossAna.loc[N, :] = [qq1, qq2, samplesize, , , ]
                N += 1
                continue
            try:
                cdata = contingency(fo, alpha=0.05)
            except:
                crossAna.loc[N, :] = [qq1, qq2, samplesize, , , ]
                N += 1
                continue
            if cdata:
                result = cdata['significant']['result']
                pvalue = cdata['significant']['pvalue']
                summary = cdata['summary']['summary']
            else:
                result = (- 2)
                pvalue = (- 2)
                summary = '没有找到结论'
            summary = '\n'.join(summary.splitlines()[1:])
            if (len(summary) == 0):
                summary = '没有找到结论'
            crossAna.loc[N, :] = [qq1, qq2, samplesize, pvalue, result, summary]
            N += 1
    crossAna.to_excel(Writer, '交叉分析表', index=False)
    Writer.save()