Series imported but unused error Python
Question: 
    import numpy as np
    from pandas import Series, DataFrame
    import pandas as pd
    import matplotlib.pyplot as plt
    
    iris_df = DataFrame()
    
    iris_data_path = 'Z:\WORK\Programming\Python\irisdata.csv'
    
    iris_df = pd.read_csv(iris_data_path,index_col=False,header=None,encoding='utf-8')
    
    iris_df.columns = ['sepal length','sepal width','petal length','petal width','class']
    
    print iris_df.columns.values
    print iris_df.head()
    print iris_df.tail()
    irisX = irisdata[['sepal length','sepal width','petal length','petal width']]
    print irisX.tail()
    irisy = irisdata['class']
    print irisy.head()
    print irisy.tail()
    
    colors = ['red','green','blue']
    markers = ['o','>','x']
    
    irisyn = np.where(irisy=='Iris-setosa',0,np.where(irisy=='Iris-virginica',2,1))
    
    Col0 = irisdata['sepal length']
    Col1 = irisdata['sepal width']
    Col2 = irisdata['petal length']
    Col3 = irisdata['petal width']
    
    plt.figure(num=1,figsize=(16,10))
    plt.subplot(2,3.1)
    for i in range(len(colors)):
        xs = Col0[irisyn==i]
        xy = Col1[irisyn==i]
        plt.scatter(xs,xy,color=colors[i],marker=markers[i])
    plt.legend( ('Iris-setosa', 'Iris-versicolor', 'Iris-virginica') )
    plt.xlabel(irisdata.columns[0])
    plt.ylabel(irisdata.columns[1])
    
    plt.subplot(2,3,2)
    for i in range(len(colors)):
        xs = Col0[irisyn==i]
        xy = Col2[irisyn==i]
        plt.scatter(xs,xy,color=colors[i],marker=markers[i])
    plt.xlabel(irisdata.columns[0])
    plt.ylabel(irisdata.columns[2])
    
    plt.subplot(2,3,3)
    for i in range(len(colors)):
        xs = Col0[irisyn==i]
        xy = Col3[irisyn==i]
        plt.scatter(xs,xy,color=colors[i],marker=markers[i])
    plt.xlabel(irisdata.columns[0])
    plt.ylabel(irisdata.columns[3])
    
    plt.subplot(2,3,4)
    for i in range(len(colors)):
        xs = Col1[irisyn==i]
        xy = Col2[irisyn==i]
        plt.scatter(xs,xy,color=colors[i],marker=markers[i])
    plt.xlabel(irisdata.columns[1])
    plt.ylabel(irisdata.columns[2])
    
    plt.subplot(2,3,5)
    for i in range(len(colors)):
        xs = Col1[irisyn==i]
        xy = Col3[irisyn==i]
        plt.scatter(xs,xy,color=colors[i],marker=markers[i])
    plt.xlabel(irisdata.columns[1])
    plt.ylabel(irisdata.columns[3])
    
    plt.subplot(2,3,6)
    for i in range(len(colors)):
        xs = Col2[irisyn==i]
        xy = Col3[irisyn==i]
        plt.scatter(xs,xy,color=colors[i],marker=markers[i])
    plt.xlabel(irisdata.columns[2])
    plt.ylabel(irisdata.columns[3])
    plt.show()
    

This is code from Howard Bandy's book Quantitative Technical Analysis. The
problem is that it is giving me errors even though I typed it out exactly like
it is in the book.

I still get the series imported but unused and undefined name irisdata
errors/warnings.

This is in the console:

Code:

    
    
      runfile('Z:/WORK/Programming/Python/Scripts/irisplotpairsdata2.py', wdir='//AMN/annex/WORK/Programming/Python/Scripts')
    ['sepal length' 'sepal width' 'petal length' 'petal width' 'class']
       sepal length  sepal width  petal length  petal width        class
    0           5.1          3.5           1.4          0.2  Iris-setosa
    1           4.9          3.0           1.4          0.2  Iris-setosa
    2           4.7          3.2           1.3          0.2  Iris-setosa
    3           4.6          3.1           1.5          0.2  Iris-setosa
    4           5.0          3.6           1.4          0.2  Iris-setosa
         sepal length  sepal width  petal length  petal width           class
    145           6.7          3.0           5.2          2.3  Iris-virginica
    146           6.3          2.5           5.0          1.9  Iris-virginica
    147           6.5          3.0           5.2          2.0  Iris-virginica
    148           6.2          3.4           5.4          2.3  Iris-virginica
    149           5.9          3.0           5.1          1.8  Iris-virginica
    Traceback (most recent call last):
    
      File "<ipython-input-100-f0b2002668bd>", line 1, in <module>
        runfile('Z:/WORK/Programming/Python/Scripts/irisplotpairsdata2.py', wdir='//AMN/annex/WORK/Programming/Python/Scripts')
    
      File "C:\MyPrograms\Spyder(Python)\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
        execfile(filename, namespace)
    
      File "C:\MyPrograms\Spyder(Python)\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
        exec(compile(scripttext, filename, 'exec'), glob, loc)
    
      File "Z:/WORK/Programming/Python/Scripts/irisplotpairsdata2.py", line 24, in <module>
        irisX = irisdata[['sepal length','sepal width','petal length','petal width']]
    
    TypeError: list indices must be integers, not list
    

Obviously, the program does not run.

I'm using spyder with python 2.7. Which is the platform he was using in the
book.

Thanks for any insight.


Answer: Well Python is not wrong. You imported Series but never used, which is a
warning that does not cause crash. The crash happens because you are
dereferencing a variable, `irisdata`, which was never defined before. (Ctrl +
f irisdata in your code and take a look.) Judging by your code,
`irisdata`probably needs to contain the parsed data of
`Z:\WORK\Programming\Python\irisdata.csv` doesn't it? So you need to parse
that out and assign it to `irisdata`. See [this
post](http://stackoverflow.com/questions/24662571/python-import-csv-to-list)

eg.

    
    
    import csv
    ...
    irisdata = list(csv.reader(open(iris_data_path, 'rb')))
    

