pandas使用

发布时间:2019-03-13 23:15:58编辑:auto阅读(2184)

    pandas数据导入:

      

     1 import pymysql
     2 import pandas as pd
     3 
     4 #导入csv文件
     5 data = pd.read_csv('file_name')
     6 
     7 #导入excel文件
     8 data = pd.read_excel('file_name')
     9 
    10 #从mysql导入数据
    11 conn = pymysql.connect(
    12     host = '127.0.0.1',
    13     user = 'user_name',
    14     password = 'password'
    15     db = 'db_name')
    16 sql = 'SELECT * FROM tb_name'
    17 data = pd.read_sql(sql, conn)
    18 
    19 #转为DataFrame类型
    20 df = pd.DataFrame(data)

     

关键字