Python 导入 pandas.plotting 的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44102532/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:43:42  来源:igfitidea点击:

Problems importing pandas.plotting

pythonpandas

提问by frmsaul

When I import pandas, everything is fine and working. Yet, when I try to import something from pandas.plottingim getting an error. What could be the source of this?

当我导入熊猫时,一切都很好并且工作正常。但是,当我尝试从pandas.plottingim导入某些内容时出现错误。这可能是什么原因?

Here is how the output looks like:

下面是输出的样子:

>>> import pandas
>>> from pandas.plotting import scatter_matrix
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named plotting

The pandas version Im using is: 0.19.2

我使用的熊猫版本是: 0.19.2

回答by spies006

Unfortunately, it looks as though there has been some confusion around the movement of that module. The plottingmodule has been moved from pandas.tools.plottingto pandas.plotting. The difficulty is most likely stemming from the fact that as of version 0.19, the pandas.plottinglibrary did not exist.

不幸的是,该模块的移动似乎有些混乱。该plotting模块已经从移动pandas.tools.plottingpandas.plotting。困难很可能源于这样一个事实,即从 0.19 版本开始,该pandas.plotting库不存在。

The current version is version 0.22. If you receive this error, the best practice is to update your version of pandas to the most recent version.

当前版本为 0.22 版。如果您收到此错误,最佳做法是将您的 Pandas 版本更新到最新版本。

If, for some reason, you are unable to do this, the correct code for earlier versions of pandas would be

如果由于某种原因您无法执行此操作,则早期版本的 Pandas 的正确代码将是

from pandas.tools.plotting import scatter_matrix

The correct code for current versions of pandas would be

当前版本的熊猫的正确代码是

from pandas.plotting import scatter_matrix

回答by IKnewThat

If you get this warning:

如果您收到此警告:

main:1: FutureWarning: 'pandas.tools.plotting.scatter_matrix' is deprecated, import 'pandas.plotting.scatter_matrix' instead.

main:1: FutureWarning: 'pandas.tools.plotting.scatter_matrix' 已弃用,改为导入 'pandas.plotting.scatter_matrix'。

import pandas.plotting

or

或者

from pandas.plotting import scatter_matrix

https://github.com/pandas-dev/pandas/pull/13579/files/fe8b918a7c7f322a6806d3b262b7b36bbd01da80#diff-52364fb643114f3349390ad6bcf24d8f

https://github.com/pandas-dev/pandas/pull/13579/files/fe8b918a7c7f322a6806d3b262b7b36bbd01da80#diff-52364fb643114f3349390ad6bcf24d8f

回答by Mr. Echfield

I figured out that most cases when the errors come up on the import scatter_matrix, it is because you have not restarted your jupyter notebooks for a while. Before I run the code; from pandas.tools.plotting import scatter_matrix I make sure I restart my jupyter notebook and run the code. Everything works just fine from then on.

我发现在导入 scatter_matrix 时出现错误的大多数情况是因为您有一段时间没有重新启动 jupyter 笔记本。在我运行代码之前;from pandas.tools.plotting import scatter_matrix 我确保重新启动我的 jupyter notebook 并运行代码。从那时起一切都很好。

回答by Jade Cacho

Just use this in importing scatter_matrix:

只需在导入 scatter_matrix 时使用它:

import pandas.plotting
# insert your scatter_matrix code here and run
# there should be no error messages (unless a new one)

To remove the array texts, you can put a ";" at the end of the code

要删除数组文本,您可以输入“;” 在代码的末尾

import pandas.plotting
scatter_matrix(df, ...); #put the semi-colon here