赞
踩
CSV- 绘制气温图表
# highs_lows_Jul.py 最高温及最低温 import csv from matplotlib import pyplot as plt from datetime import datetime # 从文件中获取最高气温 filename = 'data/sitka_weather_07-2014.csv' with open(filename) as f: # 打开文件 reader = csv.reader(f) # 调用csv.reader(),创建一个与文件相关联的阅读器对象 header_row = next(reader) # 阅读下一行(标题行) """ for index, column_header in enumerate(header_row): # 获取索引及值 print(index, column_header) """ """ dates = [datetime.strptime(row[0], '%Y-%m-%d') for row in reader] # 使用strptime方法设置日期的格式 highs = [int((int(row[1]) - 32) / 1.8) for row in reader] # Max TemperatureF列 每行的[1]索引处,并将华氏度转换为摄氏度 """ datas = [[datetime.strptime(row[0], '%Y-%m-%d'), int((int(row[1]) - 32) / 1.8)] for row in reader] dates = [row[0] for row in datas] # or [datas[row][0] for row in range(len(datas))] highs = [row[1] fo
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。