![]() |
VOOZH | about |
Categorical Data is data that corresponds to the Categorical Variable. A Categorical Variable is a variable that takes fixed, a limited set of possible values. For example Gender, Blood group, a person having country residential or not, etc.
Characteristics of Categorical Data :
Example :
A Binary Data is a Data which uses two possible states or values i.e. 0 and 1.Binary data is mostly used in various fields like in Computer Science we use it as under name Bit(Binary Digit), in Digital Electronic and mathematics we use it as under name Truth Values, and we use name Binary Variable in Statistics.
Characteristics :
Example :
Our task is to convert Categorical data into Binary Data as shown below in python :
👁 ImageStep-by-step Approach:
Step 1) In order to convert Categorical Data into Binary Data we use some function which is available in Pandas Framework. That's why Pandas framework is imported
Step2) After that a list is created and data is entered as shown below.
Step 3) After that Dataframe is created using pd.DataFrame() and here we add extra line i.e. print(data_frame) in order to show the Categorical Data Output as shown below:
Output:
Step 4) Till step 3 we get Categorical Data now we will convert it into Binary Data. So for that, we have to the inbuilt function of Pandas i.e. get_dummies() as shown:
Here we use get_dummies() for only Gender column because here we want to convert Categorical Data to Binary data only for Gender Column.
Here we get output in binary code for Gender Column only. Here we have two options to use it wisely:
In the below program we used the first option and Write code accordingly as shown below:
Output:
Below is the complete program based on the above approach:
Output: