def cross_chart(data, code, cross_class, filename=u'交叉分析报告', cross_qlist=None, delclass=None, plt_dstyle=None, cross_order=None, reverse_display=False, total_display=True, max_column_chart=20, save_dstyle=None, template=None):
    "使用帮助\n    data: 问卷数据，包含交叉变量和所有的因变量\n    code: 数据编码\n    cross_class: 交叉变量，单选题或者多选题，例如：Q1\n    filename：文件名,用于PPT和保存相关数据\n    cross_list: 需要进行交叉分析的变量，缺省为code中的所有变量\n    delclass: 交叉变量中需要删除的单个变量，缺省空\n    plt_dstyle: 绘制图表需要用的数据类型，默认为百分比表，可以选择['TGI'、'CHI'、'TWI']等\n    save_dstyle: 需要保存的数据类型，格式为列表。\n    cross_order: 交叉变量中各个类别的顺序，可以缺少\n    total_display: PPT绘制图表中是否显示总体情况\n    max_column_chart: 列联表的列数，小于则用柱状图，大于则用条形图\n    template: PPT模板信息，{'path': 'layouts':}缺省用自带的。\n    "
    if plt_dstyle:
        plt_dstyle = plt_dstyle.upper()
    if (not cross_qlist):
        try:
            cross_qlist = list(sorted(code, key=(lambda c: int(re.findall('\\d+', c)[0]))))
        except:
            cross_qlist = list(code.keys())
    if (cross_class in cross_qlist):
        cross_qlist.remove(cross_class)
    sample_len = data[code[cross_class]['qlist']].notnull().T.any().sum()
    if (code[cross_class]['qtype'] == u'单选题'):
        cross_class_freq = data[code[cross_class]['qlist'][0]].value_counts()
        cross_class_freq[u'合计'] = cross_class_freq.sum()
        cross_class_freq.rename(index=code[cross_class]['code'], inplace=True)
    elif (code[cross_class]['qtype'] == u'多选题'):
        cross_class_freq = data[code[cross_class]['qlist']].sum()
        cross_class_freq[u'合计'] = cross_class_freq.sum()
        cross_class_freq.rename(index=code[cross_class]['code'], inplace=True)
    elif (code[cross_class]['qtype'] == u'排序题'):
        tmp = qtable(data, code, cross_class)
        cross_class_freq = tmp['fo'][u'综合']
        cross_class_freq[u'合计'] = cross_class_freq.sum()
    prs = (rpt.Report(template) if template else rpt.Report())
    if (not os.path.exists('.\\out')):
        os.mkdir('.\\out')
    Writer = pd.ExcelWriter((('.\\out\\' + filename) + u'.xlsx'))
    Writer_save = {}
    if save_dstyle:
        for dstyle in save_dstyle:
            Writer_save[(u'Writer_' + dstyle)] = pd.ExcelWriter((((('.\\out\\' + filename) + u'_') + dstyle) + '.xlsx'))
    result = {}
    cross_columns = list(cross_class_freq.index)
    cross_columns = [r for r in cross_columns if (r != u'合计')]
    cross_columns = ((['内容', '题型'] + cross_columns) + [u'总体', u'显著性检验'])
    conclusion = pd.DataFrame(index=cross_qlist, columns=cross_columns)
    conclusion.to_excel(Writer, u'索引')
    prs.add_cover(title=filename)
    title = u'说明'
    summary = (((u'交叉题目为' + cross_class) + u': ') + code[cross_class]['content'])
    summary = ((summary + '\n') + u'各类别样本量如下：')
    prs.add_slide(data={'data': cross_class_freq, 'slide_type': 'table'}, title=title, summary=summary)
    data_column = data[code[cross_class]['qlist']]
    for qq in cross_qlist:
        qtitle = code[qq]['content']
        qlist = code[qq]['qlist']
        qtype = code[qq]['qtype']
        if (not (set(qlist) <= set(data.columns))):
            continue
        data_index = data[qlist]
        sample_len = data_column.iloc[list(data_index.notnull().T.any()), :].notnull().T.any().sum()
        summary = None
        if (qtype not in [u'单选题', u'多选题', u'排序题', u'矩阵单选题']):
            continue
        try:
            if reverse_display:
                result_t = crosstab(data_column, data_index, code_index=code[cross_class], code_column=code[qq])
            else:
                result_t = crosstab(data_index, data_column, code_index=code[qq], code_column=code[cross_class])
        except:
            print('脚本在处理{}时出了一天小问题.....')
            continue
        if (('fo' in result_t) and ('fop' in result_t)):
            t = result_t['fop']
            t1 = result_t['fo']
            qsample = result_t['sample_size']
        else:
            continue
        if (t is None):
            continue
        if (cross_order and (not reverse_display)):
            if (u'总体' not in cross_order):
                cross_order = (cross_order + [u'总体'])
            cross_order = [q for q in cross_order if (q in t.columns)]
            t = pd.DataFrame(t, columns=cross_order)
            t1 = pd.DataFrame(t1, columns=cross_order)
        if (cross_order and reverse_display):
            cross_order = [q for q in cross_order if (q in t.index)]
            t = pd.DataFrame(t, index=cross_order)
            t1 = pd.DataFrame(t1, index=cross_order)
        "在crosstab中已经重排了\n        if 'code_order' in code[qq] and qtype!='矩阵单选题':\n            code_order=code[qq]['code_order']\n            if reverse_display:\n                #code_order=[q for q in code_order if q in t.columns]\n                if u'总体' in t1.columns:\n                    code_order=code_order+[u'总体']\n                t=pd.DataFrame(t,columns=code_order)\n                t1=pd.DataFrame(t1,columns=code_order)\n            else:\n                #code_order=[q for q in code_order if q in t.index]\n                t=pd.DataFrame(t,index=code_order)\n                t1=pd.DataFrame(t1,index=code_order)\n        "
        t.fillna(0, inplace=True)
        t1.fillna(0, inplace=True)
        t2 = pd.concat([t, t1], axis=1)
        t2.to_excel(Writer, qq, index_label=qq, float_format='%.3f')
        Writer_rows = len(t2)
        pd.DataFrame(qsample, columns=['样本数']).to_excel(Writer, qq, startrow=(Writer_rows + 2))
        Writer_rows += (len(qsample) + 2)
        cdata = contingency(t1, alpha=0.05)
        result[qq] = cdata
        if cdata:
            summary = cdata['summary']['summary']
            if save_dstyle:
                for dstyle in save_dstyle:
                    cdata[dstyle].to_excel(Writer_save[(u'Writer_' + dstyle)], qq, index_label=qq, float_format='%.2f')
        if (qtype in [u'单选题', u'多选题', u'排序题']):
            plt_data = (t * 100)
        else:
            plt_data = t.copy()
        if (abs((1 - plt_data.sum())) <= (0.01 + 1e-17)).all():
            plt_data = (plt_data * 100)
        if ('fw' in result_t):
            plt_data = result_t['fw']
            if (cross_order and (not reverse_display)):
                if (u'总体' not in cross_order):
                    cross_order = (cross_order + [u'总体'])
                cross_order = [q for q in cross_order if (q in plt_data.index)]
                plt_data = pd.DataFrame(plt_data, index=cross_order)
            plt_data.to_excel(Writer, qq, startrow=(Writer_rows + 2))
            Writer_rows += len(plt_data)
        if (plt_dstyle and isinstance(cdata, dict) and (plt_dstyle in cdata)):
            plt_data = cdata[plt_dstyle]
        title = ((((qq + '[') + qtype) + ']: ') + qtitle)
        if (not summary):
            summary = u'这里是结论区域.'
        if ('significant' in cdata):
            sing_result = cdata['significant']['result']
            sing_pvalue = cdata['significant']['pvalue']
        else:
            sing_result = (- 2)
            sing_pvalue = (- 2)
        footnote = u'显著性检验的p值为{:.3f},数据来源于{},样本N={}'.format(sing_pvalue, qq, sample_len)
        conclusion.loc[qq, :] = qsample
        conclusion.loc[(qq, [u'内容', u'题型'])] = pd.Series({u'内容': code[qq]['content'], u'题型': code[qq]['qtype']})
        conclusion.loc[(qq, u'显著性检验')] = sing_result
        if ((not total_display) and (u'总体' in plt_data.columns)):
            plt_data.drop([u'总体'], axis=1, inplace=True)
        if (len(plt_data) > max_column_chart):
            prs.add_slide(data={'data': plt_data[::(- 1)], 'slide_type': 'chart', 'type': 'BAR_CLUSTERED'}, title=title, summary=summary, footnote=footnote)
        else:
            prs.add_slide(data={'data': plt_data, 'slide_type': 'chart', 'type': 'COLUMN_CLUSTERED'}, title=title, summary=summary, footnote=footnote)
        if ((qtype == u'排序题') and ('TOP1' in result_t)):
            plt_data = (result_t['TOP1'] * 100)
            if (cross_order and (not reverse_display)):
                if (u'总体' not in cross_order):
                    cross_order = (cross_order + [u'总体'])
                cross_order = [q for q in cross_order if (q in plt_data.columns)]
                plt_data = pd.DataFrame(plt_data, columns=cross_order)
            if (cross_order and reverse_display):
                cross_order = [q for q in cross_order if (q in plt_data.index)]
                plt_data = pd.DataFrame(plt_data, index=cross_order)
            if ('code_order' in code[qq]):
                code_order = code[qq]['code_order']
                if reverse_display:
                    if (u'总体' in t1.columns):
                        code_order = (code_order + [u'总体'])
                    plt_data = pd.DataFrame(plt_data, columns=code_order)
                else:
                    plt_data = pd.DataFrame(plt_data, index=code_order)
            plt_data.fillna(0, inplace=True)
            title = ('[TOP1]' + title)
            if (len(plt_data) > max_column_chart):
                prs.add_slide(data={'data': plt_data[::(- 1)], 'slide_type': 'chart', 'type': 'BAR_CLUSTERED'}, title=title, summary=summary, footnote=footnote)
            else:
                prs.add_slide(data={'data': plt_data, 'slide_type': 'chart', 'type': 'COLUMN_CLUSTERED'}, title=title, summary=summary, footnote=footnote)
    '\n    # ==============小结页=====================\n    difference=pd.Series(difference,index=total_qlist_0)\n    '
    if plt_dstyle:
        filename = ((filename + '_') + plt_dstyle)
    try:
        prs.save((('.\\out\\' + filename) + u'.pptx'))
    except:
        prs.save((('.\\out\\' + filename) + u'_副本.pptx'))
    conclusion.to_excel(Writer, '索引')
    Writer.save()
    if save_dstyle:
        for dstyle in save_dstyle:
            Writer_save[(u'Writer_' + dstyle)].save()
    return result
使用帮助
data: 问卷数据，包含交叉变量和所有的因变量
code: 数据编码
cross_class: 交叉变量，单选题或者多选题，例如：Q1
filename：文件名,用于PPT和保存相关数据
cross_list: 需要进行交叉分析的变量，缺省为code中的所有变量
delclass: 交叉变量中需要删除的单个变量，缺省空
plt_dstyle: 绘制图表需要用的数据类型，默认为百分比表，可以选择['TGI'、'CHI'、'TWI']等
save_dstyle: 需要保存的数据类型，格式为列表。
cross_order: 交叉变量中各个类别的顺序，可以缺少
total_display: PPT绘制图表中是否显示总体情况
max_column_chart: 列联表的列数，小于则用柱状图，大于则用条形图
template: PPT模板信息，{'path': 'layouts':}缺省用自带的。
def cross_chart(data, code, cross_class, filename=u'交叉分析报告', cross_qlist=None, delclass=None, plt_dstyle=None, cross_order=None, reverse_display=False, total_display=True, max_column_chart=20, save_dstyle=None, template=None):
    "使用帮助\n    data: 问卷数据，包含交叉变量和所有的因变量\n    code: 数据编码\n    cross_class: 交叉变量，单选题或者多选题，例如：Q1\n    filename：文件名,用于PPT和保存相关数据\n    cross_list: 需要进行交叉分析的变量，缺省为code中的所有变量\n    delclass: 交叉变量中需要删除的单个变量，缺省空\n    plt_dstyle: 绘制图表需要用的数据类型，默认为百分比表，可以选择['TGI'、'CHI'、'TWI']等\n    save_dstyle: 需要保存的数据类型，格式为列表。\n    cross_order: 交叉变量中各个类别的顺序，可以缺少\n    total_display: PPT绘制图表中是否显示总体情况\n    max_column_chart: 列联表的列数，小于则用柱状图，大于则用条形图\n    template: PPT模板信息，{'path': 'layouts':}缺省用自带的。\n    "
    if plt_dstyle:
        plt_dstyle = plt_dstyle.upper()
    if (not cross_qlist):
        try:
            cross_qlist = list(sorted(code, key=(lambda c: int(re.findall('\\d+', c)[0]))))
        except:
            cross_qlist = list(code.keys())
    if (cross_class in cross_qlist):
        cross_qlist.remove(cross_class)
    sample_len = data[code[cross_class]['qlist']].notnull().T.any().sum()
    if (code[cross_class]['qtype'] == u'单选题'):
        cross_class_freq = data[code[cross_class]['qlist'][0]].value_counts()
        cross_class_freq[u'合计'] = cross_class_freq.sum()
        cross_class_freq.rename(index=code[cross_class]['code'], inplace=True)
    elif (code[cross_class]['qtype'] == u'多选题'):
        cross_class_freq = data[code[cross_class]['qlist']].sum()
        cross_class_freq[u'合计'] = cross_class_freq.sum()
        cross_class_freq.rename(index=code[cross_class]['code'], inplace=True)
    elif (code[cross_class]['qtype'] == u'排序题'):
        tmp = qtable(data, code, cross_class)
        cross_class_freq = tmp['fo'][u'综合']
        cross_class_freq[u'合计'] = cross_class_freq.sum()
    prs = (rpt.Report(template) if template else rpt.Report())
    if (not os.path.exists('.\\out')):
        os.mkdir('.\\out')
    Writer = pd.ExcelWriter((('.\\out\\' + filename) + u'.xlsx'))
    Writer_save = {}
    if save_dstyle:
        for dstyle in save_dstyle:
            Writer_save[(u'Writer_' + dstyle)] = pd.ExcelWriter((((('.\\out\\' + filename) + u'_') + dstyle) + '.xlsx'))
    result = {}
    cross_columns = list(cross_class_freq.index)
    cross_columns = [r for r in cross_columns if (r != u'合计')]
    cross_columns = ((['内容', '题型'] + cross_columns) + [u'总体', u'显著性检验'])
    conclusion = pd.DataFrame(index=cross_qlist, columns=cross_columns)
    conclusion.to_excel(Writer, u'索引')
    prs.add_cover(title=filename)
    title = u'说明'
    summary = (((u'交叉题目为' + cross_class) + u': ') + code[cross_class]['content'])
    summary = ((summary + '\n') + u'各类别样本量如下：')
    prs.add_slide(data={'data': cross_class_freq, 'slide_type': 'table'}, title=title, summary=summary)
    data_column = data[code[cross_class]['qlist']]
    for qq in cross_qlist:
        qtitle = code[qq]['content']
        qlist = code[qq]['qlist']
        qtype = code[qq]['qtype']
        if (not (set(qlist) <= set(data.columns))):
            continue
        data_index = data[qlist]
        sample_len = data_column.iloc[list(data_index.notnull().T.any()), :].notnull().T.any().sum()
        summary = None
        if (qtype not in [u'单选题', u'多选题', u'排序题', u'矩阵单选题']):
            continue
        try:
            if reverse_display:
                result_t = crosstab(data_column, data_index, code_index=code[cross_class], code_column=code[qq])
            else:
                result_t = crosstab(data_index, data_column, code_index=code[qq], code_column=code[cross_class])
        except:
            print('脚本在处理{}时出了一天小问题.....')
            continue
        if (('fo' in result_t) and ('fop' in result_t)):
            t = result_t['fop']
            t1 = result_t['fo']
            qsample = result_t['sample_size']
        else:
            continue
        if (t is None):
            continue
        if (cross_order and (not reverse_display)):
            if (u'总体' not in cross_order):
                cross_order = (cross_order + [u'总体'])
            cross_order = [q for q in cross_order if (q in t.columns)]
            t = pd.DataFrame(t, columns=cross_order)
            t1 = pd.DataFrame(t1, columns=cross_order)
        if (cross_order and reverse_display):
            cross_order = [q for q in cross_order if (q in t.index)]
            t = pd.DataFrame(t, index=cross_order)
            t1 = pd.DataFrame(t1, index=cross_order)
        "在crosstab中已经重排了\n        if 'code_order' in code[qq] and qtype!='矩阵单选题':\n            code_order=code[qq]['code_order']\n            if reverse_display:\n                #code_order=[q for q in code_order if q in t.columns]\n                if u'总体' in t1.columns:\n                    code_order=code_order+[u'总体']\n                t=pd.DataFrame(t,columns=code_order)\n                t1=pd.DataFrame(t1,columns=code_order)\n            else:\n                #code_order=[q for q in code_order if q in t.index]\n                t=pd.DataFrame(t,index=code_order)\n                t1=pd.DataFrame(t1,index=code_order)\n        "
        t.fillna(0, inplace=True)
        t1.fillna(0, inplace=True)
        t2 = pd.concat([t, t1], axis=1)
        t2.to_excel(Writer, qq, index_label=qq, float_format='%.3f')
        Writer_rows = len(t2)
        pd.DataFrame(qsample, columns=['样本数']).to_excel(Writer, qq, startrow=(Writer_rows + 2))
        Writer_rows += (len(qsample) + 2)
        cdata = contingency(t1, alpha=0.05)
        result[qq] = cdata
        if cdata:
            summary = cdata['summary']['summary']
            if save_dstyle:
                for dstyle in save_dstyle:
                    cdata[dstyle].to_excel(Writer_save[(u'Writer_' + dstyle)], qq, index_label=qq, float_format='%.2f')
        if (qtype in [u'单选题', u'多选题', u'排序题']):
            plt_data = (t * 100)
        else:
            plt_data = t.copy()
        if (abs((1 - plt_data.sum())) <= (0.01 + 1e-17)).all():
            plt_data = (plt_data * 100)
        if ('fw' in result_t):
            plt_data = result_t['fw']
            if (cross_order and (not reverse_display)):
                if (u'总体' not in cross_order):
                    cross_order = (cross_order + [u'总体'])
                cross_order = [q for q in cross_order if (q in plt_data.index)]
                plt_data = pd.DataFrame(plt_data, index=cross_order)
            plt_data.to_excel(Writer, qq, startrow=(Writer_rows + 2))
            Writer_rows += len(plt_data)
        if (plt_dstyle and isinstance(cdata, dict) and (plt_dstyle in cdata)):
            plt_data = cdata[plt_dstyle]
        title = ((((qq + '[') + qtype) + ']: ') + qtitle)
        if (not summary):
            summary = u'这里是结论区域.'
        if ('significant' in cdata):
            sing_result = cdata['significant']['result']
            sing_pvalue = cdata['significant']['pvalue']
        else:
            sing_result = (- 2)
            sing_pvalue = (- 2)
        footnote = u'显著性检验的p值为{:.3f},数据来源于{},样本N={}'.format(sing_pvalue, qq, sample_len)
        conclusion.loc[qq, :] = qsample
        conclusion.loc[(qq, [u'内容', u'题型'])] = pd.Series({u'内容': code[qq]['content'], u'题型': code[qq]['qtype']})
        conclusion.loc[(qq, u'显著性检验')] = sing_result
        if ((not total_display) and (u'总体' in plt_data.columns)):
            plt_data.drop([u'总体'], axis=1, inplace=True)
        if (len(plt_data) > max_column_chart):
            prs.add_slide(data={'data': plt_data[::(- 1)], 'slide_type': 'chart', 'type': 'BAR_CLUSTERED'}, title=title, summary=summary, footnote=footnote)
        else:
            prs.add_slide(data={'data': plt_data, 'slide_type': 'chart', 'type': 'COLUMN_CLUSTERED'}, title=title, summary=summary, footnote=footnote)
        if ((qtype == u'排序题') and ('TOP1' in result_t)):
            plt_data = (result_t['TOP1'] * 100)
            if (cross_order and (not reverse_display)):
                if (u'总体' not in cross_order):
                    cross_order = (cross_order + [u'总体'])
                cross_order = [q for q in cross_order if (q in plt_data.columns)]
                plt_data = pd.DataFrame(plt_data, columns=cross_order)
            if (cross_order and reverse_display):
                cross_order = [q for q in cross_order if (q in plt_data.index)]
                plt_data = pd.DataFrame(plt_data, index=cross_order)
            if ('code_order' in code[qq]):
                code_order = code[qq]['code_order']
                if reverse_display:
                    if (u'总体' in t1.columns):
                        code_order = (code_order + [u'总体'])
                    plt_data = pd.DataFrame(plt_data, columns=code_order)
                else:
                    plt_data = pd.DataFrame(plt_data, index=code_order)
            plt_data.fillna(0, inplace=True)
            title = ('[TOP1]' + title)
            if (len(plt_data) > max_column_chart):
                prs.add_slide(data={'data': plt_data[::(- 1)], 'slide_type': 'chart', 'type': 'BAR_CLUSTERED'}, title=title, summary=summary, footnote=footnote)
            else:
                prs.add_slide(data={'data': plt_data, 'slide_type': 'chart', 'type': 'COLUMN_CLUSTERED'}, title=title, summary=summary, footnote=footnote)
    '\n    # ==============小结页=====================\n    difference=pd.Series(difference,index=total_qlist_0)\n    '
    if plt_dstyle:
        filename = ((filename + '_') + plt_dstyle)
    try:
        prs.save((('.\\out\\' + filename) + u'.pptx'))
    except:
        prs.save((('.\\out\\' + filename) + u'_副本.pptx'))
    conclusion.to_excel(Writer, '索引')
    Writer.save()
    if save_dstyle:
        for dstyle in save_dstyle:
            Writer_save[(u'Writer_' + dstyle)].save()
    return result