process data

Posted 吴悟无

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了process data相关的知识,希望对你有一定的参考价值。

def connect_mysql(sql, oper_type="select", data_l=None):
    conn = pymysql.connect(host=localhost, user="root", password="123",
                           database="work", port=3306)
    cur = conn.cursor()
    if oper_type == "insert":
        cur.executemany(sql, data_l)
        conn.commit()
    else:
        cur.execute(sql)
    result = cur.fetchall()
    # print(type(result), "result")
    conn.close()
    return result


def process_jobs(field_name):
    sql = "select j." + field_name + " FROM personal_jobs j"
    column_name = connect_mysql(sql, oper_type="select")
    row_total = (len(column_name))
    row_category = set(column_name)

    # init category dict
    category_dict = {}
    for k in row_category:
        category_dict[k] = 0

    # calculate amount
    cal_nmu = 0
    for k in row_category:
        for r in column_name:
            if r == k:
                cal_nmu += 1
        category_dict[k] = cal_nmu
        cal_nmu = 0
    print(type(category_dict.items()), category_dict.items())
    print(row_total, len(category_dict.items()))
    return row_total, category_dict

process_jobs("job_salary")

 

以上是关于process data的主要内容,如果未能解决你的问题,请参考以下文章

Nginx——Nginx启动报错Job for nginx.service failed because the control process exited with error code(代码片段

apriori片段代码

需要对特定 R 代码片段的解释

[React Testing] Use Generated Data in Tests with tests-data-bot to Improve Test Maintainability(代码片段

Swift新async/await并发中利用Task防止指定代码片段执行的数据竞争(Data Race)问题

Swift新async/await并发中利用Task防止指定代码片段执行的数据竞争(Data Race)问题