Python實(shí)現(xiàn)Mysql數(shù)據(jù)統(tǒng)計(jì)及numpy統(tǒng)計(jì)函數(shù)
Python實(shí)現(xiàn)Mysql數(shù)據(jù)統(tǒng)計(jì)的實(shí)例代碼如下所示:
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)計(jì)函數(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]):
返回一個(gè)同緯度數(shù)組,每個(gè)元素都是之前所有元素的 累加和,參數(shù)是 number 或 ndarray
np.cumprod(x [, axis]):
返回一個(gè)同緯度數(shù)組,每個(gè)元素都是之前所有元素的 累乘積,參數(shù)是 number 或 ndarray
總結(jié)
以上所述是小編給大家介紹的Python實(shí)現(xiàn)Mysql數(shù)據(jù)統(tǒng)計(jì)及numpy統(tǒng)計(jì)函數(shù),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- Python如何統(tǒng)計(jì)函數(shù)調(diào)用的耗時(shí)
- python統(tǒng)計(jì)函數(shù)被調(diào)用次數(shù)的實(shí)現(xiàn)
- 利用Python實(shí)現(xiàn)簡(jiǎn)單的Excel統(tǒng)計(jì)函數(shù)
- python?DataFrame數(shù)據(jù)分組統(tǒng)計(jì)groupby()函數(shù)的使用
- python統(tǒng)計(jì)函數(shù)庫scipy.stats的用法解析
- Python使用統(tǒng)計(jì)函數(shù)繪制簡(jiǎn)單圖形實(shí)例代碼
- Python中統(tǒng)計(jì)函數(shù)運(yùn)行耗時(shí)的方法
- python常見統(tǒng)計(jì)分析處理函數(shù)解讀
相關(guān)文章
python爬蟲之urllib庫常用方法用法總結(jié)大全
urllib是python自帶的請(qǐng)求庫,各種功能相比較之下也是比較完備的,下面這篇文章主要給大家介紹了關(guān)于python爬蟲之urllib庫常用方法用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-11-11利用python?pywifi實(shí)現(xiàn)破解WiFi密碼
家里沒有怎么辦,只要你會(huì)Python,辦法總比困難多,本文就利用pywifi?這個(gè)庫實(shí)驗(yàn)一下如何破解Wi-Fi?密碼,注意,該方法僅可用來研究學(xué)習(xí)所用,需要的朋友可以參考下2024-03-03詳解Python中math和decimal模塊的解析與實(shí)踐
在Python中,math?和?decimal?模塊是處理數(shù)學(xué)運(yùn)算的重要工具,本文將深入探討這兩個(gè)模塊的基礎(chǔ)知識(shí),并通過實(shí)際的代碼示例演示它們的用法,希望對(duì)大家有所幫助2024-02-02Pandas||過濾缺失數(shù)據(jù)||pd.dropna()函數(shù)的用法說明
這篇文章主要介紹了Pandas||過濾缺失數(shù)據(jù)||pd.dropna()函數(shù)的用法說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-05-05Python數(shù)據(jù)分析?Numpy?的使用方法
這篇文章主要介紹了Python數(shù)據(jù)分析?Numpy?的使用方法,Numpy?是一個(gè)Python擴(kuò)展庫,專門做科學(xué)計(jì)算,也是大部分Python科學(xué)計(jì)算庫的基礎(chǔ),關(guān)于其的使用方法,需要的小伙伴可以參考下面文章內(nèi)容2022-05-05