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]):
所有元素的標(biāo)準(zhǔn)差,參數(shù)是 number 或 ndarray
np.var(x [, axis]):
所有元素的方差,參數(shù)是 number 或 ndarray
np.argmax(x [, axis]):
最大值的下標(biāo)索引值,參數(shù)是 number 或 ndarray
np.argmin(x [, axis]):
最小值的下標(biāo)索引值,參數(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ù),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(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ù)運(yùn)行耗時的方法
- python常見統(tǒng)計分析處理函數(shù)解讀
相關(guān)文章
python爬蟲之urllib庫常用方法用法總結(jié)大全
urllib是python自帶的請求庫,各種功能相比較之下也是比較完備的,下面這篇文章主要給大家介紹了關(guān)于python爬蟲之urllib庫常用方法用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-11-11利用python?pywifi實現(xiàn)破解WiFi密碼
家里沒有怎么辦,只要你會Python,辦法總比困難多,本文就利用pywifi?這個庫實驗一下如何破解Wi-Fi?密碼,注意,該方法僅可用來研究學(xué)習(xí)所用,需要的朋友可以參考下2024-03-03Pandas||過濾缺失數(shù)據(jù)||pd.dropna()函數(shù)的用法說明
這篇文章主要介紹了Pandas||過濾缺失數(shù)據(jù)||pd.dropna()函數(shù)的用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-05-05Python數(shù)據(jù)分析?Numpy?的使用方法
這篇文章主要介紹了Python數(shù)據(jù)分析?Numpy?的使用方法,Numpy?是一個Python擴(kuò)展庫,專門做科學(xué)計算,也是大部分Python科學(xué)計算庫的基礎(chǔ),關(guān)于其的使用方法,需要的小伙伴可以參考下面文章內(nèi)容2022-05-05