经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » NumPy » 查看文章
Python实现Mysql数据统计及numpy统计函数
来源:jb51  时间:2019/7/16 8:34:45  对本文有异议

Python实现Mysql数据统计的实例代码如下所示:

  1. import pymysql
  2. import xlwt
  3. excel=xlwt.Workbook(encoding='utf-8')
  4. sheet=excel.add_sheet('Mysql数据库')
  5. sheet.write(0,0,'库名')
  6. sheet.write(0,1,'表名')
  7. sheet.write(0,2,'数据条数')
  8. db=pymysql.connect('192.168.1.74','root','123456','xx1')
  9. cursor=db.cursor()
  10. sql="select TABLE_SCHEMA as 'database',TABLE_NAME as table_name from information_schema.TABLES where TABLE_SCHEMA in ('my1','my2','t1','xx1');"
  11. i=0
  12. try:
  13. cursor.execute(sql)
  14. res1=cursor.fetchall()
  15. for row in res1:
  16. database=row[0]
  17. table=row[1]
  18. c1=row[0]+'.'+row[1]
  19. c2='select count(*) from %s'%c1
  20. try:
  21. cursor.execute(c2)
  22. res2=cursor.fetchall()
  23. for num in res2:
  24. count=num[0]
  25. i=i+1
  26. sheet.write(i,0,database)
  27. sheet.write(i,1,table)
  28. sheet.write(i,2,count)
  29. except:
  30. print('Error,Please check your code')
  31. except:
  32. print('Error,Please check your code')
  33. excel.save('C:\\Users\\user\\DeskTop\\mysql.xls')
  34. 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统计函数,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对w3xue网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号