pandas.DataFrame:.hist() 与 .plot.hist() 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40776252/
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
pandas.DataFrame: .hist() vs .plot.hist() methods
提问by Kiv
On pandas.DataFrame
in 0.19 there are two hist methods:
在pandas.DataFrame
0.19有两种方法HIST:
At first I thought they were the same, but actually they take different arguments. Is one going to be deprecated in a future release, is there a different use case for each, or what's the story?
起初我以为他们是一样的,但实际上他们采取了不同的论点。是否会在未来的版本中被弃用,每个都有不同的用例,或者故事是什么?
采纳答案by AlexG
I don't have a definitive answer for you. One thing I noticed is that DataFrame.hist
returns a list of axes objects and DataFrame.plot.hist
returns only one. For example:
我没有明确的答案给你。我注意到的一件事是DataFrame.hist
返回一个轴对象列表并且DataFrame.plot.hist
只返回一个。例如:
# Making up data
df = pd.DataFrame({'value1': np.random.normal(1, 1, 99),
'value2': [-1]*33 + [0]*33 + [1]*33})
df.hist()
df.plot.hist()
回答by OldGeeksGuide
Looking at the docs, http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.plot.hist.htmland http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.hist.html, it looks like plot.hist
is a function that takes a few histogram specific options but then passes on all other keyword args to plot()
, while hist takes a large number of keyword args directly. I would guess that this is primarily to create a simpler, more consistent API, i.e. rather than having 15 different functions that each take a large number of kwargs
, just focus on the specialized args while the rest are consistent with plot()
查看文档,http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.plot.hist.html和http://pandas.pydata.org/pandas-docs /stable/generated/pandas.DataFrame.hist.html,它看起来像是plot.hist
一个函数,它接受一些直方图特定的选项,然后将所有其他关键字参数传递给plot()
,而 hist 直接接受大量关键字参数。我猜这主要是为了创建一个更简单、更一致的 API,即不是有 15 个不同的函数,每个函数都需要大量的kwargs
,只关注专门的 args 而其余的与plot()
cf:
参考:
New in version 0.17.0: Each plot kind has a corresponding method on the DataFrame.plot accessor: df.plot(kind='line') is equivalent to df.plot.line()
0.17.0 新版功能:每个绘图种类在 DataFrame.plot 访问器上都有相应的方法: df.plot(kind='line') 等效于 df.plot.line()
In addition, the plot* functions return axes
, which could be useful for chaining and other things.
此外, plot* 函数 return axes
,这对于链接和其他事情可能很有用。