Let's import the pandas libary.
I am importing a table of contents so it is easy to understand how the new column is created.
In this case I am importing the list of monarchies published on wikipedia:
I delete all the columns that I dont need for this example and I add the 'Realm / Kingdom' column as an index of the table to make it clearer.
Now it is time to create the new column based on the values from another column.
In this case, I want to create a new column called 'monarchy type' based on the values from the column 'Type'.
So, for example, if monarchy type is 'Constitutional' the new column will have a value 1, 2 if it is 'mixed' and so on.
First I want to list all unique values for the 'Type' column.
I specify the value for each type of monarchy.