介绍
这篇文章主要介绍Python怎么实现Mysql数据统计及numpy统计函数,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
Python实现Mysql数据统计的实例代码如下所示:
import pymysql import xlwt excel=xlwt.Workbook(编码=& # 39;utf - 8 # 39;) 表=excel.add_sheet (& # 39; Mysql数据库& # 39;) sheet.write(0, 0, & # 39;库名& # 39;) sheet.write(0 1 & # 39;表名& # 39;) sheet.write(0 2 & # 39;数据条数& # 39;) db=pymysql.connect(& # 39; 192.168.1.74& # 39; & # 39;根# 39;,& # 39;123456 & # 39;,& # 39;民# 39;) 光标=db.cursor () sql=皊elect  TABLE_SCHEMA as & # 39;数据库# 39;,TABLE_NAME as TABLE_NAME 得到information_schema.TABLES where TABLE_SCHEMA 拷贝(& # 39;当我# 39;& # 39;my2& # 39;, & # 39; t1 # 39;, & # 39;民# 39;);“ 我=0 试一试: ,cursor.execute (sql) ,res1=cursor.fetchall () ,for row  res1拷贝: ,数据库行[0]=,表=行[1] ,c1=行[0]+ & # 39;强生# 39;+行[1] ,c2=& # 39; select  count(*),得到% & # 39;% c1 ,试一试: cursor.execute才能(c2) 它才能=cursor.fetchall () for 才能;num 拷贝它: 数=才能num [0] 我=我才能+ 1 sheet.write才能(我0数据库) sheet.write才能(我1表) sheet.write才能(我2数) ,除了: 打印才能(& # 39;错误,Please check  your 代码# 39;) 除了: ,打印(& # 39;错误,Please check  your 代码# 39;) excel.save (& # 39; C: \ \用户用户桌面\ \ \ \ \ \ mysql.xls& # 39;) db.close ()
<>强PS:下面看下Python数据分析numpy统计函数强>
np。意味着(x(轴):
引用>
所有元素的平均值,参数是数字或ndarray
np。总和(x(轴):
所有元素的和,参数是数字或ndarray
np。马克斯(x(轴):
所有元素的最大值,参数是数字或ndarray
np。分钟(x(轴):
所有元素的最小值,参数是数字或ndarray
np。性病(x(轴):
所有元素的标准差,参数是数字或ndarray
np。var (x(轴):
所有元素的方差,参数是数字或ndarray
np。argmax (x(轴):
最大值的下标索引值,参数是数字或ndarray
np。argmin (x(轴):
最小值的下标索引值,参数是数字或ndarray
np。cumsum (x(轴):
返回一个同纬度数组,每个元素都是之前所有元素的累加和,参数是数字或ndarray
np。cumprod (x(轴):
返回一个同纬度数组,每个元素都是之前所有元素的累乘积,参数是数字或ndarray
Python怎么实现Mysql数据统计及numpy统计函数