Support Vector Classifier Strategy Code

I am trying to copy the code for machine learning in Spyder from the Support Vector Classifier Strategy Code  NoteBook (CSV file is the same folder as the Spyder folder)



this is what I wrote:


-- coding: utf-8 --

"""

Spyder Editor



This is a temporary script file.

"""

#machine learning

from sklearn.svm import SVC

from sklearn.metrics import accuracy_score



#data manipulation

import pandas as pd

import numpy as np



import tkinter as tk

from tkinter import filedialog

import pandas as pd





#plot



import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')



#ignore warnings

import warnings

warnings.filterwarnings("ignore")



#fecth data

Df = Df.read_csv("SPY")

Df = Df.dropna()

Df = Df.set_index(Df.date)

Df = Df.drop(columns='date') 



This is the error I have gotten:



Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]

Type "copyright", "credits" or "license" for more information.



IPython 7.8.0 – An enhanced Interactive Python.



runfile('C:/Users/jorge/.spyder-py3/prueba.py', wdir='C:/Users/jorge/.spyder-py3')

Traceback (most recent call last):



  File "<ipython-input-1-2a4d78934b57>", line 1, in <module>

    runfile('C:/Users/jorge/.spyder-py3/prueba.py', wdir='C:/Users/jorge/.spyder-py3')



  File "C:\Users\jorge\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile

    execfile(filename, namespace)



  File "C:\Users\jorge\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile

    exec(compile(f.read(), filename, 'exec'), namespace)



  File "C:/Users/jorge/.spyder-py3/prueba.py", line 30, in <module>

    Df = Df.read_csv("SPY")



NameError: name 'Df' is not defined

Hello Jorge,



In your fetch data code: 



#fecth data

Df = Df.read_csv("SPY")

Df = Df.dropna()

Df = Df.set_index(Df.date)

Df = Df.drop(columns='date') 



Df.read_csv("SPY") is using the object Df to call the read_csv function. This object hasn't been defined before this line. read_csv is a function in the pandas library. You have imported the pandas library with an alias called pd. This was done in the line:



import pandas as pd




So your should instead read the data like:



Df = pd.read_csv("SPY")