Series imported but unused error Python -


import numpy np pandas import series, dataframe import pandas pd import matplotlib.pyplot 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) 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) 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) 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) 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) 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) 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 code howard bandy's book quantitative technical analysis. problem is giving me errors though typed out in book.

i still series imported unused , undefined name irisdata errors/warnings.

this in 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 integers, not list 

obviously, program not run.

i'm using spyder python 2.7. platform using in book.

thanks insight.

well python not wrong. imported series never used, warning not cause crash. crash happens because dereferencing variable, irisdata, never defined before. (ctrl + f irisdata in code , take look.) judging code, irisdataprobably needs contain parsed data of z:\work\programming\python\irisdata.csv doesn't it? need parse out , assign irisdata. see this post

eg.

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

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -