python - ValueError: time data u'Date' does not match format '%Y-%m-%d' -
i'm new python programming. looked solution error couldn't find any. i've been trying figure out what's wrong hours no luck. here's code:
import matplotlib.pyplot plt import numpy np import urllib import matplotlib.dates mdates def bytespdate2num(fmt, encoding='utf-8'): strconverter = mdates.strpdate2num(fmt) def bytesconverter(b): s = b.decode(encoding) return strconverter(s) return bytesconverter def graph_data(stock): stock_price_url = 'https://pythonprogramming.net/yahoo_finance_replacement' source_code = urllib.urlopen(stock_price_url).read().decode() stock_data = [] split_source = source_code.split('\n') line in split_source: split_line = line.split(',') if len(split_line) == 7: if 'values' not in line , 'labels' not in line: stock_data.append(line) date,openp,highp,lowp,closep,adjusted_close,vol = np.loadtxt(stock_data,delimiter=',',unpack=true,converters= {0:bytespdate2num('%y-%m-%d')}) plt.plot_date(date,closep,'-',label='price') plt.xlabel('date') plt.ylabel('price') plt.title('graph') plt.legend() plt.show() graph_data('tsla')
Comments
Post a Comment