Python實現(xiàn)Mysql數(shù)據(jù)統(tǒng)計及numpy統(tǒng)計函數(shù)
Python實現(xiàn)Mysql數(shù)據(jù)統(tǒng)計的實例代碼如下所示:
import pymysql
import xlwt
excel=xlwt.Workbook(encoding='utf-8')
sheet=excel.add_sheet('Mysql數(shù)據(jù)庫')
sheet.write(0,0,'庫名')
sheet.write(0,1,'表名')
sheet.write(0,2,'數(shù)據(jù)條數(shù)')
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數(shù)據(jù)分析numpy統(tǒng)計函數(shù)
np.mean(x [, axis]):
所有元素的平均值,參數(shù)是 number 或 ndarray
np.sum(x [, axis]):
所有元素的和,參數(shù)是 number 或 ndarray
np.max(x [, axis]):
所有元素的最大值,參數(shù)是 number 或 ndarray
np.min(x [, axis]):
所有元素的最小值,參數(shù)是 number 或 ndarray
np.std(x [, axis]):
所有元素的標準差,參數(shù)是 number 或 ndarray
np.var(x [, axis]):
所有元素的方差,參數(shù)是 number 或 ndarray
np.argmax(x [, axis]):
最大值的下標索引值,參數(shù)是 number 或 ndarray
np.argmin(x [, axis]):
最小值的下標索引值,參數(shù)是 number 或 ndarray
np.cumsum(x [, axis]):
返回一個同緯度數(shù)組,每個元素都是之前所有元素的 累加和,參數(shù)是 number 或 ndarray
np.cumprod(x [, axis]):
返回一個同緯度數(shù)組,每個元素都是之前所有元素的 累乘積,參數(shù)是 number 或 ndarray
總結(jié)
以上所述是小編給大家介紹的Python實現(xiàn)Mysql數(shù)據(jù)統(tǒng)計及numpy統(tǒng)計函數(shù),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
- Python如何統(tǒng)計函數(shù)調(diào)用的耗時
- python統(tǒng)計函數(shù)被調(diào)用次數(shù)的實現(xiàn)
- 利用Python實現(xiàn)簡單的Excel統(tǒng)計函數(shù)
- python?DataFrame數(shù)據(jù)分組統(tǒng)計groupby()函數(shù)的使用
- python統(tǒng)計函數(shù)庫scipy.stats的用法解析
- Python使用統(tǒng)計函數(shù)繪制簡單圖形實例代碼
- Python中統(tǒng)計函數(shù)運行耗時的方法
- python常見統(tǒng)計分析處理函數(shù)解讀
相關(guān)文章
詳解如何使用SQLAlchemy連接數(shù)據(jù)庫
這篇文章主要為大家詳細介紹了如何使用 SQLAlchemy 連接數(shù)據(jù)庫、建立模型、操作表、以及查詢操作表數(shù)據(jù)等內(nèi)容,感興趣的小伙伴可以跟隨小編一起學習一下2023-11-11
Python實戰(zhàn)實現(xiàn)爬取天氣數(shù)據(jù)并完成可視化分析詳解
這篇文章主要和大家分享一個用Python實現(xiàn)的小功能:獲取天氣數(shù)據(jù),進行可視化分析,帶你直觀了解天氣情況!感興趣的小伙伴可以學習一下2022-06-06
Python Pandas學習之基本數(shù)據(jù)操作詳解
本文將通過讀取一個股票數(shù)據(jù),來進行Pandas的一些基本數(shù)據(jù)操作的語法介紹。文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2022-02-02
用Python復現(xiàn)二戰(zhàn)德軍enigma密碼機
大家好,本篇文章主要講的是用Python復現(xiàn)二戰(zhàn)德軍enigma密碼機,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2022-01-01

