Now, as we discussed in our teary lecture, we need to convert all of our categorical variables and
to a numerical variable.
And we do that by creating dummy variables.
So let's see how to create a dummy variable in Python.
We'll first take a sample of our data, will use D.F. and we will apply Hegg method.
You can see there are two categorical variables.
That is truly underscore available and it is taking value.
Yes and no.
And there is another categorical variable, which is Johna.
And it is taking value, thriller, drama, comedy and action.
Will convert this categorical variables into dummy variable.
And you know that the numbers of dummy variable should be one minus the numbers of category in each
variable.
So we will need one variable for trivia.
Really one and three variables for John are variable.
Now, creating dummy variables and pandas is very easy.
You just have to use get demis method of pandas.
So we will write Beedi Dot Guide Demis.
And to hear our first parameter is data, since our duties, D.F. will write D.F..
Then there are two parameters, prefix and prefix separator.
These two are for naming your dummy variable columns.
And we are happy with their default value, we don't want to change these values.
And the next is columns.
This is a parameter where we specify what columns do we need the dummy variables for?
Since there are two columns that is truly available and John, it will pass this two columns as a list
in this column parameter.
So will write columns equal to then will create a list of two aloose forces through the available.
And Johna, since this two are work at all what we call variable.
Then there is another parameter that is Grop underscored first.
If you remember, we discussed that the number of dummy variables should be equal to and minus one,
that is number of categories, minus one.
To do that, we have to write Grop underscored first, equally true, if we want a separate dummy variable
for all the categories.
So our treaty of a label have two categories, the US and No.
And if we want to dummy variables for this variable, we can choose, Grob underscored for us as follows.
But as we discussed, we want and minus one variables.
We will select Grop underscored for us as escarole and we are again saving this table and do our data
frame.
So we are equating it to the yes.
And we are changing categorical variables and numeric variable.
We'll run this.
Now, again, we take a sample of over the data frame using B, if not tagged.
We executed this.
You can see now we have converted our categorical variables into numerical variable, our first variable
is 3D underscore, available underscore.
Yes, this is one everywhere.
Our 3D and it's available.
Very well.
It was, yes.
And zero, where our 3D underscore available.
Very well, it was No.
Now we have three variables for over Johnette.
Categorical variable.
We have Johna underscore comedy, Johna Underscore Grama and John that underscore thriller, these are
zero and one according to our categorical variable.
Jonah, if the Janner was comedy, then we will have one in the Johnette underscore comedy with one.
This is how we convert categorical variables and to numerical variables so that we can run our regression
or classification or any other techniques on our data.