def save_data(data, filename=u'data.xlsx', code=None):
    '保存问卷数据到本地\n    根据filename后缀选择相应的格式保存\n    如果有code,则保存按文本数据\n    '
    savetype = os.path.splitext(filename)[1][1:]
    data1 = data.copy()
    if code:
        for qq in code.keys():
            qtype = code[qq]['qtype']
            qlist = code[qq]['qlist']
            if (qtype == u'单选题'):
                data1[qlist[0]].replace(code[qq]['code'], inplace=True)
                data1.rename(columns={qq: '{}({})'.format(qq, code[qq]['content'])}, inplace=True)
            elif (qtype == u'矩阵单选题'):
                data1[code[qq]['qlist']].replace(code[qq]['code'], inplace=True)
                tmp1 = code[qq]['qlist']
                tmp2 = ['{}({})'.format(q, code[qq]['code_r'][q]) for q in tmp1]
                data1.rename(columns=dict(zip(tmp1, tmp2)), inplace=True)
            elif (qtype in [u'排序题']):
                tmp = data[qlist]
                tmp = tmp.rename(columns=code[qq]['code'])
                tmp = dataCode_to_text(tmp)
                ind = list(data1.columns).index(qlist[0])
                qqname = '{}({})'.format(qq, code[qq]['content'])
                data1.insert(ind, qqname, tmp)
                tmp1 = code[qq]['qlist']
                tmp2 = ['{}_{}'.format(qq, code[qq]['code'][q]) for q in tmp1]
                data1.rename(columns=dict(zip(tmp1, tmp2)), inplace=True)
            elif (qtype in [u'多选题']):
                tmp = data[qlist]
                tmp = tmp.rename(columns=code[qq]['code'])
                tmp = dataCode_to_text(tmp)
                ind = list(data1.columns).index(qlist[0])
                qqname = '{}({})'.format(qq, code[qq]['content'])
                data1.insert(ind, qqname, tmp)
                for q in qlist:
                    data1[q].replace({0: '', 1: code[qq]['code'][q]}, inplace=True)
                tmp2 = ['{}_{}'.format(qq, code[qq]['code'][q]) for q in qlist]
                data1.rename(columns=dict(zip(qlist, tmp2)), inplace=True)
            else:
                data1.rename(columns={qq: '{}({})'.format(qq, code[qq]['content'])}, inplace=True)
    if ((savetype == u'xlsx') or (savetype == u'xls')):
        data1.to_excel(filename, index=False)
    elif (savetype == u'csv'):
        data1.to_csv(filename, index=False)
保存问卷数据到本地
根据filename后缀选择相应的格式保存
如果有code,则保存按文本数据
def save_data(data, filename=u'data.xlsx', code=None):
    '保存问卷数据到本地\n    根据filename后缀选择相应的格式保存\n    如果有code,则保存按文本数据\n    '
    savetype = os.path.splitext(filename)[1][1:]
    data1 = data.copy()
    if code:
        for qq in code.keys():
            qtype = code[qq]['qtype']
            qlist = code[qq]['qlist']
            if (qtype == u'单选题'):
                data1[qlist[0]].replace(code[qq]['code'], inplace=True)
                data1.rename(columns={qq: '{}({})'.format(qq, code[qq]['content'])}, inplace=True)
            elif (qtype == u'矩阵单选题'):
                data1[code[qq]['qlist']].replace(code[qq]['code'], inplace=True)
                tmp1 = code[qq]['qlist']
                tmp2 = ['{}({})'.format(q, code[qq]['code_r'][q]) for q in tmp1]
                data1.rename(columns=dict(zip(tmp1, tmp2)), inplace=True)
            elif (qtype in [u'排序题']):
                tmp = data[qlist]
                tmp = tmp.rename(columns=code[qq]['code'])
                tmp = dataCode_to_text(tmp)
                ind = list(data1.columns).index(qlist[0])
                qqname = '{}({})'.format(qq, code[qq]['content'])
                data1.insert(ind, qqname, tmp)
                tmp1 = code[qq]['qlist']
                tmp2 = ['{}_{}'.format(qq, code[qq]['code'][q]) for q in tmp1]
                data1.rename(columns=dict(zip(tmp1, tmp2)), inplace=True)
            elif (qtype in [u'多选题']):
                tmp = data[qlist]
                tmp = tmp.rename(columns=code[qq]['code'])
                tmp = dataCode_to_text(tmp)
                ind = list(data1.columns).index(qlist[0])
                qqname = '{}({})'.format(qq, code[qq]['content'])
                data1.insert(ind, qqname, tmp)
                for q in qlist:
                    data1[q].replace({0: , 1: code[qq]['code'][q]}, inplace=True)
                tmp2 = ['{}_{}'.format(qq, code[qq]['code'][q]) for q in qlist]
                data1.rename(columns=dict(zip(qlist, tmp2)), inplace=True)
            else:
                data1.rename(columns={qq: '{}({})'.format(qq, code[qq]['content'])}, inplace=True)
    if ((savetype == u'xlsx') or (savetype == u'xls')):
        data1.to_excel(filename, index=False)
    elif (savetype == u'csv'):
        data1.to_csv(filename, index=False)