Python實現Mysql數據統(tǒng)計及numpy統(tǒng)計函數
Python實現Mysql數據統(tǒng)計的實例代碼如下所示:
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統(tǒng)計函數
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數據統(tǒng)計及numpy統(tǒng)計函數,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
相關文章
Pandas||過濾缺失數據||pd.dropna()函數的用法說明
這篇文章主要介紹了Pandas||過濾缺失數據||pd.dropna()函數的用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-05-05

