'ValueError: hist method requires numerical columns, nothing to plot

I was going through a tutorial, but as I was running the code in an IDE, an error occurred. The link to the tutorial is here: https://thecleverprogrammer.com/2020/12/29/house-price-prediction-with-python/. This is the code I have so far: First cell:

import pandas as pd
url = "https://raw.githubusercontent.com/ageron/handson-ml/master/datasets/housing/housing.csv"
names = ['longitude','latitude','housing_median_age','total_rooms','total_bedrooms',         'population','households','median_income','median_house_value','ocean_proximity']
housing = pd.read_csv(url, names=names)
housing.head()

Second cell:

housing.info()

Third cell:

housing.ocean_proximity.value_counts()

Fourth cell:

import matplotlib.pyplot as plt
housing.hist(bins=50,figsize=(10, 8))
plt.show()

It's in the second line of the fourth cell that I have an error. As the title states, the compiler says ValueError: hist method requires numerical columns, nothing to plot. Why is this?



Solution 1:[1]

Because the data type in your dataframe is not numeric, you can use info() to view the data type. If the data type is "object", you cannot draw a picture. You can try to convert the data into "float" or "int" and then use hist()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chaoran huang