I'm working on a chess dataset, where I got a column for move_1, move_2, move_3 and so on... each of these columns has the 'play code' made by the player. Each row is for a specific game and there are about 1000 rows.
result move_1 move_2 move_3 ...
1 e4 d4 Nc3 ...
1 d4 Nf3 c4 ...
1 e4 d3 Nd2 ...
1 d4 c4 d5 ...
0 d4 c4 Nc3 ...
keeps going down...
what is the best way for me to change each unique value in each row/column to an assigned integer so I can do some analysis on it? I've done the following:
chess_df['move_2'].replace(to_replace=['Nf3', 'c4', 'd3','d4', 'Nc3'],
value= [3, 2, 4, 1, 7],
inplace=True)
where each 'play code' has it's assigned integer. So, 'd4' = 1, 'c4 = 2 and so on, on ALL rows.
Problem is, this is NOT a great way of doing it since I need to find each and every unique code and replace it for a unique integer by columns... This will take ages, and it will be really confusing.
What I want is, move_1 column got 1000 rows and 45 unique 'play codes'. So each play code in it would become a number ranging from 1-45.
move_2 column has 1000 rows with 89 unique values where 25 of them are also in move_1 column. So I need to assign the 25 numbers already assigned in move_1 column + 64 new numbers. And so on...
So my question is:
How can I through Python code, create something that would automate the process of changing the 'play code' into a unique integer on all rows and columns?