安装navicat,新建school数据库,并建student(学号 int,姓名 Text,年龄 int)表,插入3个人,代码实现。 我的答案: import sqlite3 con=sqlite3.connect("D:\\sql\\SQL1\\test.db3") a=con.cursor() # a.execute(''' # CREATE TABLE COMPANY # (NUM INT PRIMARY KEY NOT NULL, # NAME TEXT NOT NULL, # AGE INT NOT NULL # ) # ''') a.execute(''' INSERT INTO COMPANY(NUM,NAME ,AGE) VALUES (1,'小明',20) ''') con.commit() con.close()
将以下的000001.csv所有内容写入到zhengquan.db3数据库的date表中。
我的答案:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import sqlite3
b=pd.read_excel("D:\\Project\\19jx2\\000001.xlsx",sheet_name=0)
con=sqlite3.connect("D:\\sql\\zhengquan4.db3")
a=con.cursor()
# a.execute('''
#
# CREATE TABLE COMPANY
#
# ("日期" TEXT PRIMARY KEY ,
# "股票代码" TEXT ,
# "名称" TEXT ,
# "收盘价" TEXT ,
# "最高价" TEXT ,
# "最低价" TEXT ,
# "开盘价" TEXT ,
# "前收盘" TEXT ,
# "涨跌额" TEXT ,
# "涨跌幅" TEXT ,
# "成交量" TEXT ,
# "成交金额" TEXT
# )
#
# ''')
for i in b.iterrows():
a.execute('''
INSERT INTO COMPANY('日期','股票代码' ,'名称','收盘价','最高价','最低价','开盘价','前收盘','涨跌额','涨跌幅','成交量','成交金额')
VALUES ("%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s")
'''%(i[1]['日期'],i[1]['股票代码'] ,i[1]['名称'],i[1]['收盘价'],i[1]['最高价'],i[1]['最低价'],i[1]['开盘价'],i[1]['前收盘'],i[1]['涨跌额'],i[1]['涨跌幅'],i[1]['成交量'],i[1]['成交金额']))
con.commit()
con.close()