读写不同数据源的数据:
1、安装pandas
pip install pandas 或者 conda install pandas
(一些镜像可能不支持最新python版本,所以当pip找不到合适的version的时候,使用conda进行安装,可以先conda search pandas,看看哪些镜像源支持)
2、导入pandas
import pandas (as pd)
我们有时候读取数据需要批量读取,如下:
import os
os.chdir(r'your documents path')
3、读取数据库数据
from sqlalchemy import create_engine
engin=create_engine('mysql+pymysql://root:***(密码)@127.0.0.1:3306/test?charset=utf8')
read_sql_table只能够读取数据库的某一个表格,不能实现查询的操作。
pd.read_sql_table(table_name,con,schema=None,index_col=None,coerce_float=True,columns=None)
read_sql_query则只能实现查询操作,不能直接读取数据库中的某个表。
pd.read_sql_query(sql,con,index_col=None,coerce_float=True)
pd.read_sql(sql,con,index_col=None,coerce_float=True,columns=None)
*******such as:********
pd.read_sql_table('xxxxx',con=engin)
pd.read_sql_query('select * from xxxx',con=engin)
pd.read_sql('xxxxx',con=engin)
pd.read_sql('select * from xxxx',con=engin)