题目:
1.拿到平安银行一年的股票数据 csv文件
2.里面一共244个交易日,我们读取csv文件,然后找到成交量(amount)大于1百万手的交易日的数据3.然后把大于1百万手的那天的如下数据:
open
high
low
close
amount
写入excel文件import csv,xlwt def reader_csv(path): res = [] file = open(path) data = csv.reader(file) for row in data: if data.line_num==1: continue elif float(row[-1])>=1000000: res.append([row[3],row[4],row[5],row[6],row[-1]]) return res def exchange_to_excel(data): workbook = xlwt.Workbook() sheet = workbook.add_sheet('data') row_num = 0 for line in data: cell_num = 0 for i in line: sheet.write(row_num,cell_num,i) cell_num = cell_num+1 row_num = row_num + 1 workbook.save('/Users/lu-zyr/Downloads/000001.xls') def main (): path = "/Users/lu-zyr/Downloads/000001.csv" result = reader_csv(path) for i in result: print(i) exchange_to_excel(result) if __name__=='__main__': main()
运行结果
['10.59', '10.66', '10.47', '10.59', '1126374.829'] ['10.75', '10.8', '10.52', '10.57', '1099654.683'] ['10.57', '10.88', '10.57', '10.85', '1466899.416'] ['10.61', '10.72', '10.49', '10.57', '1123173.219'] ['10.41', '10.65', '10.38', '10.54', '1126736.143'] ['10.71', '10.73', '10.4', '10.55', '1716198.382'] ['10.95', '11.04', '10.82', '10.92', '1409457.171'] ['11.04', '11.16', '10.83', '11.09', '2439179.135'] ['10.99', '11.05', '10.76', '10.83', '1679443.449'] ['10.95', '10.99', '10.75', '10.91', '1252156.775'] ['10.78', '11.08', '10.73', '10.9', '1641371.787'] ['11.2', '11.24', '10.62', '10.75', '1725932.497'] ['11.29', '11.31', '10.96', '11.18', '1448843.512'] ['10.8', '11.29', '10.71', '11.29', '1855823.739'] ['10.9', '11.33', '10.8', '11.04', '2026171.911'] ['11.2', '11.22',
python—实战训练(五)
最新推荐文章于 2021-04-02 10:43:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)