pandas使用

2020-01-19 14:27:12 浏览数 (1)

pandas数据导入:

代码语言:javascript复制
 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)

0 人点赞