使用python将excel数据导入数据库过程详解
更新时间:2019年08月27日 10:24:00 作者:大长胡子 正在上传… 我要评论
这篇文章主要介绍了使用python将excel数据导入数据库过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
因为需要对数据处理,将excel数据导入到数据库,记录一下过程。
使用到的库:xlrd 和 pymysql (如果需要写到excel可以使用xlwt)
直接丢代码,使用python3,注释比较清楚。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
XXX里自行修改自己的名称。
说明:对于不规则的单元格,例如合并过的单元格会取到空值。
优化了一下这个程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
再改一下,每一万条数据写入到数据库一次
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
思考,如果数据插入有错误,怎么解决,
其实有很多数据库工具可以直接来解决这个问题,注意字符转换的格式就好。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。