Python如何读取MySQL数据库表数据
本文实例为大家分享了Python读取MySQL数据库表数据的具体代码,供大家参考,具体内容如下
环境:Python 3.6 ,Window 64bit
目的:从MySQL数据库读取目标表数据,并处理
代码:
# -*- coding: utf-8 -*- import pandas as pd import pymysql ## 加上字符集参数,防止中文乱码 dbconn=pymysql.connect( host="**********", database="kimbo", user="kimbo_test", password="******", port=3306, charset='utf8' ) #sql语句 sqlcmd="select col_name,col_type,col_desc from itf_datadic_dtl_d limit 10" #利用pandas 模块导入mysql数据 a=pd.read_sql(sqlcmd,dbconn) #取前5行数据 b=a.head() print(b) # 读取csv数据 # pd.read_csv() # 读取excel数据 #pd.read_excel() # 读取txt数据 #pd.read_table()
结果如图:
相关推荐
huavhuahua 2020-11-20
weiiron 2020-11-16
cakecc00 2020-11-15
千锋 2020-11-15
JakobHu 2020-11-14
guangcheng 2020-11-13
xirongxudlut 2020-11-10
solarLan 2020-11-09
pythonxuexi 2020-11-08
文山羊 2020-11-07
susmote 2020-11-07
wuShiJingZuo 2020-11-05
Pythonjeff远 2020-11-06
jacktangj 2020-11-04
lousir 2020-11-04
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17