Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas DataFrame.hist() doesn't work

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

like image 636
Pred05 Avatar asked Jul 25 '18 12:07

Pred05


People also ask

How do you use Hist in pandas?

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.

How do I force a panda to display all rows?

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.

How do you plot a histogram for a DataFrame in Python?

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.

How do I force pandas to show all columns?

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.


2 Answers

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()
like image 141
JoschJava Avatar answered Oct 30 '22 00:10

JoschJava


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.

like image 43
SkrewEverything Avatar answered Oct 29 '22 23:10

SkrewEverything