2016-09-15 97 views
-2

的代码实际上是从工作 使用通过蟒蛇和Spyder的IDE 最新版本的Python有了Spyder的 code screenshotPython库但未使用的导入

from pandas import Series, DataFrame 
import pandas as pd 
import numpy as np 
import matplotlib as plt 
import os 
from sklearn.cross_validation import train_test_split 
from sklearn.tree import DecisionTreeClassifier 
import sklearn.metrics 
from sklearn.metrics import classification_report 

代码分析表明大熊猫库中导入应用程序重新编写但未使用。

请大家帮帮忙蟒蛇noobie

感谢您的意见,我学习!

我已经既没有进口的建议和控制台返回所看到的SS console error messages

>>> runfile('C:/Users/dbldee/Desktop/TREES/Decisiontree.py', wdir='C:/Users/dbldee/Desktop/TREES') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Users\dbldee\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile 
    execfile(filename, namespace) 
    File "C:\Users\dbldee\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile 
    exec(compile(f.read(), filename, 'exec'), namespace) 
    File "C:/Users/dbldee/Desktop/TREES/Decisiontree.py", line 42, in <module> 
    classifier = classifier.fit(pred_train,tar_train) 
TypeError: fit() missing 1 required positional argument: 'y' 
>>> 

这表明该问题可能与该文件的读取错误运行脚本?

+0

您应该能够删除这些导入,但应该在之后测试您的代码,以确保这不会导致任何意外问题。 – Jaco

+0

您能否提供一个示例 - 如果您遇到这些导入问题? – estebanpdl

+0

@flippy,这部分脚本似乎是防止执行<从熊猫进口系列问题的来源,数据帧 进口熊猫作为PD 进口numpy的作为NP 进口OS 进口matplotlib.pylab从sklearn.cross_validation PLT 进口train_test_split 从sklearn.tree进口DecisionTreeClassifier 从sklearn.metrics导入classification_report 进口sklearn.metrics os.chdir( 'C:\\用户\\ dbldee \\桌面\\ TREES') “”” 数据工程与分析“ AH_data = pd.read_csv(“tree_addhealth.csv”) – dbldee

回答

2

Spyder正在做一个static check来帮助你的Python程序的正确性。您可能可以按照原样运行,但该工具正在帮助您使用Python风格和简洁。

尝试删除线

import pandas as pd 

,它应该停止抱怨。试着按照IDE的建议打破和改变程序,而不用担心打破程序,这将使你学习。

+1

我真的认为人们现在依赖IDE /文本编辑器。 +1告诉他不要害怕违背IDE的建议,只看到会发生什么。你应该知道你为什么做事,而不是盲目地做。 –