pandas 导入但未使用的 Python 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39515845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python libraries imported but unused
提问by dbldee
The code is actually re-written from an application that worked Using the latest version of python via Anaconda and Spyder ide With Spyder code screenshot
该代码实际上是从一个运行的应用程序重写的通过 Anaconda 和 Spyder ide 使用最新版本的 python 使用 Spyder 代码截图
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
Code analysis show pandas library imported but unused.
代码分析显示已导入但未使用的 Pandas 库。
Please help out a python noobie
请帮助一个python noobie
thanks for the comments, I'm learning!!
谢谢评论,学习了!!
I have run the script both with and without the imports as suggested and the console return the errors as seen in the SSconsole error messages
我已经按照建议在有和没有导入的情况下运行脚本,控制台返回错误,如 SS控制台错误消息中所示
>>> 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'
>>>
Which suggests that the problem may be with reading of the file??
这表明问题可能与读取文件有关??
回答by Caio Tomazelli
Spyder is doing a static checkto help with the correctness of your python program. You probably can run it just fine as it is, but the tool is helping you with python style and conciseness.
Spyder 正在进行静态检查,以帮助检查您的 Python 程序的正确性。您可能可以按原样运行它,但该工具正在帮助您实现 Python 风格和简洁性。
Try removing the line
尝试删除该行
import pandas as pd
and it should stop complaining. Try breaking and changing the program following the ide's suggestions without fear to break the program, that is what will make you learn.
它应该停止抱怨。尝试按照ide的建议破坏和更改程序,而不必担心破坏程序,这将使您学习。