Python Pandas giving me SettingWithCopyWarning when I attempt to map a particular DataFrame column - how to fix?
I have some code that needs to replace two columns of a pandas DataFrame with the index of each value as they appear in a unique list of those values. For example:
col1, col2, col3, col4
A, 1, 2, 3
A, 1, 2, 3
B, 1, 2, 3
Should end up in the data frame as:
col1, col2, col3, col4
0, 1, 2, 3
0, 1, 2, 3
1, 1, 2, 3
since A is element 0 in the list of unique col1 values, and B is element number 1.
What I did is:
unique_vals = df['col1'].unique()
# create a map to speed up looking indexes when we...