擅长:python、mysql、java
<p>使用<a href="https://pandas.pydata.org/docs/reference/api/pandas.Categorical.html" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>In [96]: df['Mask_ProductId'] = df.ProductId.astype('category').cat.codes
In [97]: df
Out[97]:
ProductId Sales Mask_ProductId
0 AXX11 10 0
1 CS22 34 1
2 AXX11 23 0
3 FV34 45 3
4 FV34 23 3
5 DF23 54 2
6 CS22 65 1
</code></pre>