def data_auto_code(data):
    '智能判断问卷数据\n    输入\n    data: 数据框，列名需要满足Qi或者Qi_\n    输出：\n    code: 自动编码\n    '
    data = pd.DataFrame(data)
    columns = data.columns
    columns = [c for c in columns if re.match('Q\\d+', c)]
    code = {}
    for cc in columns:
        if ('_' not in cc):
            key = cc
        else:
            key = cc.split('_')[0]
        if (key not in code):
            code[key] = {}
            code[key]['qlist'] = []
            code[key]['code'] = {}
            code[key]['content'] = key
            code[key]['qtype'] = ''
        if (key == cc):
            code[key]['qlist'] = [key]
        elif re.findall((('^' + key) + '_[a-zA-Z]{0,}\\d+$'), cc):
            code[key]['qlist'].append(cc)
        elif ('qlist_open' in code[key]):
            code[key]['qlist_open'].append(cc)
        else:
            code[key]['qlist_open'] = [cc]
    for kk in code.keys():
        dd = data[code[kk]['qlist']]
        if (len(dd.columns) == 1):
            tmp = dd[dd.notnull()].iloc[:, 0].unique()
            if (dd.iloc[:, 0].value_counts().mean() >= 2):
                code[kk]['qtype'] = u'单选题'
                code[kk]['code'] = dict(zip(tmp, tmp))
            else:
                code[kk]['qtype'] = u'填空题'
                del code[kk]['code']
        else:
            tmp = set(dd[dd.notnull()].as_matrix().flatten())
            if (set(tmp) == set([0, 1])):
                code[kk]['qtype'] = u'多选题'
                code[kk]['code'] = dict(zip(code[kk]['qlist'], code[kk]['qlist']))
            elif ('R' in code[kk]['qlist'][0]):
                code[kk]['qtype'] = u'矩阵单选题'
                code[kk]['code_r'] = dict(zip(code[kk]['qlist'], code[kk]['qlist']))
                code[kk]['code'] = dict(zip(list(tmp), list(tmp)))
            else:
                code[kk]['qtype'] = u'排序题'
                code[kk]['code'] = dict(zip(code[kk]['qlist'], code[kk]['qlist']))
    return code
智能判断问卷数据
输入
data: 数据框，列名需要满足Qi或者Qi_
输出：
code: 自动编码
def data_auto_code(data):
    '智能判断问卷数据\n    输入\n    data: 数据框，列名需要满足Qi或者Qi_\n    输出：\n    code: 自动编码\n    '
    data = pd.DataFrame(data)
    columns = data.columns
    columns = [c for c in columns if re.match('Q\\d+', c)]
    code = {}
    for cc in columns:
        if ('_' not in cc):
            key = cc
        else:
            key = cc.split('_')[0]
        if (key not in code):
            code[key] = {}
            code[key]['qlist'] = []
            code[key]['code'] = {}
            code[key]['content'] = key
            code[key]['qtype'] = 
        if (key == cc):
            code[key]['qlist'] = [key]
        elif re.findall((('^' + key) + '_[a-zA-Z]{0,}\\d+$'), cc):
            code[key]['qlist'].append(cc)
        elif ('qlist_open' in code[key]):
            code[key]['qlist_open'].append(cc)
        else:
            code[key]['qlist_open'] = [cc]
    for kk in code.keys():
        dd = data[code[kk]['qlist']]
        if (len(dd.columns) == 1):
            tmp = dd[dd.notnull()].iloc[:, 0].unique()
            if (dd.iloc[:, 0].value_counts().mean() >= 2):
                code[kk]['qtype'] = u'单选题'
                code[kk]['code'] = dict(zip(tmp, tmp))
            else:
                code[kk]['qtype'] = u'填空题'
                del code[kk]['code']
        else:
            tmp = set(dd[dd.notnull()].as_matrix().flatten())
            if (set(tmp) == set([0, 1])):
                code[kk]['qtype'] = u'多选题'
                code[kk]['code'] = dict(zip(code[kk]['qlist'], code[kk]['qlist']))
            elif ('R' in code[kk]['qlist'][0]):
                code[kk]['qtype'] = u'矩阵单选题'
                code[kk]['code_r'] = dict(zip(code[kk]['qlist'], code[kk]['qlist']))
                code[kk]['code'] = dict(zip(list(tmp), list(tmp)))
            else:
                code[kk]['qtype'] = u'排序题'
                code[kk]['code'] = dict(zip(code[kk]['qlist'], code[kk]['qlist']))
    return code