I need to convert categorical values to column names and fill with zeros and ones.
x = pd.DataFrame({'province' : ['Ontario', 'Manitoba', 'Quebec'], 'species' : ['a', 'b', 'c']})
province species
0 Ontario a
1 Manitoba b
2 Quebec c
I want to reshape the data frame above so that the values in species
turn into column names, and the values of the new columns indicate presence or absence. The new data frame should look like this:
province a b c
0 Ontario 1 0 0
1 Manitoba 0 1 0
2 Quebec 0 0 1