End-to-End ML Project- Beginner friendly

34 / 95

Identifying categorical attributes

As we know that the Dtype of ocean_proximity is an object. So, it can be any Python object. So now we refer to the output of the head() method to check which python object it contains.

We can see that it contains text data. But we also notice that it has repetitive values and we can only see NEAR BAY in the first five rows. So, it can be a case that it contains the same value NEAR BAY for every instance, or it is a categorical attribute and we can see only one of its categories which is NEAR BAY in the first five instances.

We can check what is true by the value_counts() method of the DataFrame object. It displays all the categories with their count values by their side. Its syntax is -


where, data_frame is the name of the DataFrame and attribute_name is the name of the attribute. Remember, we can use this function for the whole DataFrame too instead of specifying it for only one attribute, but that doesn't provide us with much useful information.


Run the value_counts() method for ocean_proximity attribute of housing DataFrame.

Get Hint See Answer

Loading comments...