i follow the google course about machine learning. i'm on this part : pandas
But on my mac when i want to generate a chart with this command :
california_housing_dataframe.hist('housing_median_age')
it doesn't work. The python icon appear but nothing is displaying on the screen.
i have see some tips with the backend parameter into matplotlibrc but mine is equals to MacOSX and it should work ?
Thanks for help
In order to plot a histogram using pandas, chain the . hist() function to the dataframe. This will return the histogram for each numeric column in the pandas dataframe.
A function set_option() is provided by pandas to display all rows of the data frame. display. max_rows represents the maximum number of rows that pandas will display while displaying a data frame. The default value of max_rows is 10.
To plot a Histogram using Matplotlib, you need to first import the Histogram class from the Matplotlib library. The Histogram class has a plot() method which is used to plot histograms. The plot() method accepts a dataframe column as an argument. The Histogram will be plotted on the column of the dataframe.
To show all columns in Pandas we can set the option: pd. option_context - display. max_columns to None. This will show all columns in the current DataFrame.
To elaborate on the comment from T. Kelly:
You need to call plt.show(). This worked for me:
import matplotlib.pyplot as plt
california_housing_dataframe.hist('housing_median_age')
plt.show()
I'm following Google ML Crash Course(I think you are also following it based on the variable name).
I too encountered the same problem.
When I call
california_housing_dataframe.hist('housing_median_age')
It is not showing any histogram. Instead it is showing
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x12bb814e0>]],
dtype=object)
To show the histogram, add this line in your imports:
%matplotlib inline
It should show the histogram.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With