他们做不同的事情,df.hist()
将为每个Series
生成一个单独的图,而df.plot.hist()
将生成一个堆叠的单个图:
df = pd.DataFrame({
... 'length': [1.5, 0.5, 1.2, 0.9, 3],
... 'width': [0.7, 0.2, 0.15, 0.2, 1.1]
... }, index= ['pig', 'rabbit', 'duck', 'chicken', 'horse'])
df.hist(bins=3)
产生:
df.plot.hist(bins=3)
产生:
因此取决于您想要的东西,它们是针对不同用途的便捷功能。