I have some football data with two team names and some numerical data:
ar = [
["browns", "patriots", 2, 5],
["patriots", "bills", 4, 15],
["browns", "bills", 1, 10],
["eagles", "browns", 3, 11]
]
frame = pandas.DataFrame(ar, columns=['Team1', 'Team2', 'Down', 'ToGo'])
I want to turn the team names into an enumerated type, which I can do for the first team name like:
frame['Team1'], uniques = frame['Team1'].factorize()
How can I do this to both team names at the same time, so there is consistent uniques and not have missing values? Note that 'bills' is not in Team1 column, so I can't just apply the mapping (though I don't know how to do that either).
Edit: The resulting team names should look like:
Team1 Team2
0 0 1
1 1 3
2 0 3
3 2 0
so that 'browns' is labeled consistently as '0', in row 0 as Team1, and in row 3 as Team2.