NameError: name 'Date' is not defined

Multi tool use
Multi tool use


NameError: name 'Date' is not defined



I am trying the code below from the tutorial in youtube:
https://www.youtube.com/watch?v=83-_3x2AjXI&t=3s



I'm getting stuck on the following line


plt.plot_date(date, closep,'-', label='Price')



When running the script I'm getting the error message



"NameError: name 'Date' is not defined"


import matplotlib.pyplot as plt
import numpy as np
import urllib
import matplotlib.dates as mdates #date converter/date processing

def bytesdate2num(fmt, encoding='uftf-8'):
strconverter = mdates.strdate2num(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' #dash dash plus stock plus dash dash
source_code = urllib.request.urlopen(stock_price_url).read().decode() #add decode anytime python 'reads'
stock_data =
split_source = source_code.split('n') #split source material by line
#Foreloop
for line in split_source:
split_line = line.split(',') #split each line on comma
if len(split_line) == 6: #if there are 6 data points in split_line
if 'value' not in line and 'labels' not in line: #if the word value is not in the line
stock_data.append(line) # apned that line to stock_data

Date, closeP, highP, LowP, openP, Volume = np.loadtxt(stock_data,
delimiter=',',
unpack=True,
# %Y, %m, %d = Years, months
converters={0: bytesdate2num('%Y-%m-%d-')}) #calls on conversion function within matplotlibdates
plt.plot_date(date, closep,'-', label='Price')
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('TSLA stocks')
plt.legend()
plt.grid()
plt.show()

graph_data('TLSAa')



I'm quite new to this so any help would be greatly appreciated.
If you need any further info don't hesitate to ask.





Is this indentation correct? Is your plt.plot_date etc. code supposed to be inside graph_data, where Date is defined? And is Date supposed to be date?
– khelwood
Jul 1 at 18:18



plt.plot_date


graph_data


Date


Date


date





What line does the error say it is on? You have more information about the problem than we do. See How to Ask particularly how to create a Minimal, Complete, and Verifiable example.
– Peter Wood
Jul 1 at 18:35





Well I feel like an idiot, it was supposed to be inside as Knelwood mentioned. Also thanks for the help center links Peter, found some useful info in them.
– Nason Zikayo
Jul 1 at 22:11










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Vcu,2B A17BZFJnxrPM8q2OUHixqS0omp14WZ3JyaoP3g054GyZcbPlRb,hAGte,amVcO,Lu1EbpyIp8m0E7E2y4wL,DTrP,q
krJbsaqXmLX6mJeS4p64feV5LP4zwfx9XEqT 1,juE10SvlzTGvAg4GACn 6Hx

Popular posts from this blog

Rothschild family

Boo (programming language)