Python实现Mysql数据统计及numpy统计函数

作者:My木岩 时间:2024-01-18 13:15:07 

Python实现Mysql数据统计的实例代码如下所示:


import pymysql
import xlwt
excel=xlwt.Workbook(encoding='utf-8')
sheet=excel.add_sheet('Mysql数据库')
sheet.write(0,0,'库名')
sheet.write(0,1,'表名')
sheet.write(0,2,'数据条数')
db=pymysql.connect('192.168.1.74','root','123456','xx1')
cursor=db.cursor()
sql="select TABLE_SCHEMA as 'database',TABLE_NAME as table_name from information_schema.TABLES where TABLE_SCHEMA in ('my1','my2','t1','xx1');"
i=0
try:
cursor.execute(sql)
res1=cursor.fetchall()
for row in res1:
database=row[0]
table=row[1]
c1=row[0]+'.'+row[1]
c2='select count(*) from %s'%c1
try:
 cursor.execute(c2)
 res2=cursor.fetchall()
 for num in res2:
 count=num[0]
 i=i+1
 sheet.write(i,0,database)
 sheet.write(i,1,table)
 sheet.write(i,2,count)
except:
 print('Error,Please check your code')
except:
print('Error,Please check your code')
excel.save('C:\\Users\\user\\DeskTop\\mysql.xls')
db.close()

PS:下面看下Python数据分析numpy统计函数

np.mean(x [, axis]):
所有元素的平均值,参数是 number 或 ndarray
np.sum(x [, axis]):
所有元素的和,参数是 number 或 ndarray
np.max(x [, axis]):
所有元素的最大值,参数是 number 或 ndarray
np.min(x [, axis]):
所有元素的最小值,参数是 number 或 ndarray
np.std(x [, axis]):
所有元素的标准差,参数是 number 或 ndarray
np.var(x [, axis]):
所有元素的方差,参数是 number 或 ndarray
np.argmax(x [, axis]):
最大值的下标索引值,参数是 number 或 ndarray
np.argmin(x [, axis]):
最小值的下标索引值,参数是 number 或 ndarray
np.cumsum(x [, axis]):
返回一个同纬度数组,每个元素都是之前所有元素的 累加和,参数是 number 或 ndarray
np.cumprod(x [, axis]):
返回一个同纬度数组,每个元素都是之前所有元素的 累乘积,参数是 number 或 ndarray

总结

以上所述是小编给大家介绍的Python实现Mysql数据统计及numpy统计函数,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

来源:https://blog.csdn.net/weixin_42840933/article/details/85341719

标签:python,mysql,数据统计,numpy
0
投稿

猜你喜欢

  • 使用 OpenAI API 和 Python 使用 GPT-3的操作方法

    2023-10-23 20:04:05
  • nodejs处理tcp连接的核心流程

    2024-05-03 15:55:40
  • python中常用的各种数据库操作模块和连接实例

    2024-01-18 16:29:20
  • Dreamwaver 常见问答解答

    2009-07-05 18:51:00
  • Python从数据库读取大量数据批量写入文件的方法

    2024-01-27 14:48:10
  • Python制作词云图代码实例

    2023-10-24 11:20:21
  • pycharm 无法加载文件activate.ps1的原因分析及解决方法

    2022-07-11 01:00:49
  • tensorflow中Dense函数的具体使用

    2021-04-26 17:01:49
  • 一个基于flask的web应用诞生(1)

    2022-06-22 09:23:52
  • 详解Python中的数据清洗工具flashtext

    2021-10-05 01:59:47
  • Python3使用xml.dom.minidom和xml.etree模块儿解析xml文件封装函数的方法

    2023-12-19 22:42:41
  • JavaScript每天必学之基础知识

    2024-04-18 10:02:25
  • MySQL中Binary Log二进制日志文件的基本操作命令小结

    2024-01-12 22:24:20
  • Python绘制百分比堆叠柱状图并填充图案

    2023-01-25 00:49:06
  • VS2008 和.NET 3.5 Beta2常见问题的解决方案

    2007-09-23 12:33:00
  • pandas学习之df.set_index的具体使用

    2021-11-12 07:35:20
  • asp获取数据库中表名和字段名的代码

    2011-04-18 11:02:00
  • PHP基础之运算符的使用方法

    2023-11-20 17:33:55
  • Navicat15安装教程超详细步骤(最靠谱)

    2024-01-12 22:29:11
  • python中的turtle库函数简单使用教程

    2022-08-06 23:22:18
  • asp之家 网络编程 m.aspxhome.com