To transform a column of a dataframe to categorical in Python, we can use the astype()
function and pass category
as the argument to convert the column to a categorical datatype. Here's an example:
main.py313 chars14 lines
Output:
main.py52 chars4 lines
As you can see, the fruit
column is now of datatype category
.
gistlibby LogSnag