import os
from matplotlib.backends.backend_pdf import PdfPages
import pandas as pd
import matplotlib.pyplot as plt
import datetime as dt
pp = PdfPages('multipage.pdf')
pth = "D:/Technical_Data/"
for fle in os.listdir(pth):
df = pd.read_csv(os.path.join(pth, fle),usecols=(0, 4))
if not df.empty:
df=df.astype(float)
days = df['indx']
value = df['Close']
plt.plot_date(x=days, y=value,fmt="r-")
plt.title(fle)
plt.ylabel("Price")
plt.grid(True)
pp.savefig()
pp.close()
我正在遍歷目錄中的文件,並將所有圖形保存爲pdf文件。日期格式爲20150101
。ValueError:年份超出範圍pyplot
但它引發錯誤:
ValueError: year is out of range
的樣本數據
indx open High Low Close Volume
20140103 31.9823 32.1511 31.8382 32.1213 2034100
20140103 5.28 5.29 5.26 5.27 10387300
20140103 33.9 34.03 33.77 34 930800
20140103 10.62 10.63 10.51 10.6 2004500
20140103 3.42 3.49 3.42 3.49 3837600
20140103 1.69 1.71 1.685 1.705 6870300
20140103 42.5 43.61 42.3 43.47 255500
很難調試代碼,而無需輸入例。請打印'days'變量的值併發布,我懷疑問題出在那裏。 –
@TonyBabarino有問題 – nnnnmmm