zoukankan      html  css  js  c++  java
  • 预处理算法_3_新增序列

    增加新的序列

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-

    # <editable>

    def execute():
    # <editable>
    inputs = {"table": 'test', }
    params = {
    "left_columns": "id, score",
    "ind": "new_label"

    }
    '''
    载入模块
    '''
    import pandas as pd
    import numpy as np
    from sqlalchemy import create_engine
    '''
    连接数据库
    '''
    engine = create_engine('mysql+pymysql://root:123123qwe@127.0.0.1:3306/analysis')
    '''
    选择目标数据
    '''
    left_sql = 'select ' + params['left_columns'] + ' from ' + inputs['table']
    data_in = pd.read_sql_query(left_sql, engine)
    # data_in = db_utils.query(conn, 'select ' + params['columns'] + ' from ' + inputs['data_in'])

    '''
    新增自增序列
    '''
    new = np.arange(1, data_in.index.size + 1)
    new = pd.DataFrame({params['ind']: new})
    data_out = pd.concat([new, data_in], axis=1)

    '''
    将结果写出
    '''
    print(data_out)
    '''
    数据示例
    new_label id score
    0 1 1 80.0
    1 2 2 20.0
    2 3 3 NaN
    3 4 4 5.0
    4 5 5 4.0
    5 6 6 20.0
    '''


    # </editable>


    if __name__ == '__main__':
    execute()
    作者:沐禹辰
    出处:http://www.cnblogs.com/renfanzi/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
  • 相关阅读:
    docker1
    Ubuntu中安装deb包程序
    Linux性能评测工具之一:gprof篇介绍
    Lua在Linux下的安装
    gprof的使用介绍
    Linux性能评测工具之一:gprof篇
    google-perftools 分析JAVA 堆外内存
    NetHogs下载和监控
    Google perf tools for nginx
    ECLIPSE中添加TPTP插件
  • 原文地址:https://www.cnblogs.com/renfanzi/p/14476427.html
Copyright © 2011-2022 走看看