1 Star 0 Fork 0

自由民/DataAnalyse

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ImportData.py 729 Bytes
一键复制 编辑 原始数据 按行查看 历史
自由民 提交于 2016-11-02 11:42 . Begin to analyse
# -*- coding:utf-8 -*-
#导入数据库数据
import sqlite3
#打开数据库
con = sqlite3.connect("money.db")
con.text_factory = lambda x:str(x, 'gb2312')
#取得游标
cu = con.cursor()
#查询
cu.execute("select Time, Name, Amount, TypeName from Income, IncomeType where IncomeType.TypeID == Income.TypeID")
#获取结果
data = cu.fetchall()
#关闭数据库
con.close()
#显示结果
#print(data[10])
#print(cu.description[2][0])
#print(len(data))
#将数据写入csv文件
import csv
with open("money.csv", "w") as csvfile:
writer = csv.writer(csvfile)
item = []
for i in range(4):
item.append(cu.description[i][0])
writer.writerow(item)
writer.writerows(data)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zwdnet/DataAnalyse.git
git@gitee.com:zwdnet/DataAnalyse.git
zwdnet
DataAnalyse
DataAnalyse
master

搜索帮助