擅长:python、mysql、java
<p>我想你要找的是:</p>
<pre><code>modDF['RatingDecile'] = pd.cut(modDF['RatingScore'], 10, labels=range(1,11))
# or
modDF['RatingDecile'] = pd.cut(modDF['RatingScore'], 10, labels=False)
</code></pre>
<p>从<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.cut.html" rel="nofollow noreferrer">docs</a>开始:</p>
<blockquote>
<p><strong>labels</strong> : array or bool, optional<br/>
Specifies the labels for the returned bins. Must be the same length as the resulting bins. If False, returns only integer indicators of the bins. This affects the type of the output container (see below). This argument is ignored when bins is an IntervalIndex.</p>
</blockquote>
<p>此外,如果要“覆盖”整个间隔<code>[0,30]</code>,请指定箱子边缘:</p>
<pre><code>import numpy as np
modDF['RatingDecile'] = pd.cut(modDF['RatingScore'],
bins=np.linspace(0, 30, 11), labels=False)
</code></pre>
<p><strong>警告:</strong>注意<a href="https://stackoverflow.com/a/30214901">^{<cd2>} is not the same as ^{<cd3>}</a></p>