溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Python怎么實現Mysql數據統計及numpy統計函數

發布時間:2021-04-07 09:45:20 來源:億速云 閱讀:440 作者:小新 欄目:開發技術

這篇文章主要介紹Python怎么實現Mysql數據統計及numpy統計函數,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

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統計函數”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女