開發python,使用https://anaconda.cloud/
以下是
import csv
import matplotlib.pyplot as plt
from datetime import datetime
plt.rcParams["font.family"] = ["Microsoft JhengHei"] # 設定圖檔字型
fn = 'a.csv'
with open(fn, newline='', encoding='utf-8') as csvFile: # 開始csv檔案
csvReader = csv.reader(csvFile) # 讀檔案建立reader物件
headerRow = next(csvReader) # 讀取文件下一列
dates, highTemp, lowTemps = [], [], [] # 設定空串列
for row in csvReader:
try:
currentDate = datetime.strptime(row[0], "%Y/%m/%d") # 圖示設定日期格式
但出現下述
ValueError Traceback (most recent call last)
Cell In[5], line 12
10 headerRow = next(csvReader) # 讀取文件下一列
11 dates, highTemp, lowTemps = [], [], [] # 設定空串列
---> 12 for row in csvReader:
13 try:
14 currentDate = datetime.strptime(row[0], "%Y/%m/%d") # 圖示設定日期格式
ValueError: I/O operation on closed file.
請大大協助,感激不盡。