python - Plotting a histogram with Matplotlib -


for reason following line doesn't work:

plt.hist(diamonds.price) 

the following, however, work

diamonds.price.hist() 

diamonds dataframe, why can't plot using pyplot.

thanks.

as stated on pandas help,

the plot method on series , dataframe simple wrapper around plt.plot():

the plot needs know pandas’s data structures , dataframe.hist() extract in correct manner. if want plot using matplotlib, need extract data dataframe, like,

import numpy np import matplotlib.pyplot plt import pandas pd  dates = pd.date_range('1/1/2000', periods=8) df = dataframe(np.random.randn(8, 4), index=dates, columns=['a', 'b', 'c', 'd'])  plt.hist(df.values) plt.show() 

although, may not plot data in same way using pandas plot methods have discarded tabular data structure.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -