Python之pandas读取mysql中文乱码问题

 

# -*- coding: utf-8 -*-
# author:baoshan

import pandas as pd
import pymysql
config = {
    "host": "localhost",
    "port": 3306,
    "user": "root",
    "password": "123456",
    "charset": "utf8"
}
conn = pymysql.connect(**config)
sql = "select " \
      "table_schema as '数据库'," \
      "table_name as '数据表', " \
      "TABLE_COMMENT as '表注释', " \
      "round(data_length/1024/1024,2) as '数据大小(M)', " \
      "round(index_length/1024/1024,2) as '索引大小(M)', " \
      "TABLE_ROWS as '行数'" \
      "from information_schema.tables " \
      "where TABLE_SCHEMA not in ('information_schema', 'performance_schema', 'mysql') " \
      "AND TABLE_ROWS > 0"

df = pd.read_sql(sql, conn)
print(df.head())

输出结果:

          数据库                        数据表          表注释  数据大小(M)  索引大小(M)    行数
0  collection          colt_data_element          信息元     0.02     0.02    16
1  collection  colt_data_element_catalog        数据元目录     0.02     0.00    12
2  collection           colt_depart_user      部门包含的员工     0.02     0.03    16
3  collection            colt_department          委办局     0.02     0.00     6
4  collection          colt_report_audit  信息上报状态流水状态表     0.09     0.02  1072

 

pandas配合pymysql好用(pandas配合sqlalchemy就没有搞定中文乱码的问题)

 

谢谢!

转载于:https://www.cnblogs.com/zhzhang/p/11386968.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值