#!/usr/bin/env python # -*- coding:utf-8 -*- # <editable> def execute(): # <editable> ''' 载入模块 ''' from collections import Counter import pandas as pd from sqlalchemy import create_engine ''' 连接数据库 ''' engine = create_engine('mysql+pymysql://root:123123qwe@127.0.0.1:3306/analysis') ''' 选择目标数据 ''' # 生成数据 params = { "columns": "SUNACTIVITY", } inputs = {"table": '纯随机性检验'} data_sql = 'select ' + params['columns'] + ' from ' + inputs['table'] data_in = pd.read_sql_query(data_sql, engine) print(data_in) ''' 频数统计 ''' data = data_in[params['columns']] data_out = pd.DataFrame.from_dict(Counter(data), orient='index').reset_index() data_out.columns = [params['columns'], 'count'] ''' 将结果写出 ''' print(data_out) # </editable> if __name__ == '__main__': execute()