#!/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()
