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