<p>您可以使用:</p>
<ul>
<li>删除列<code>value</code></li>
<li>与<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.lt.html" rel="nofollow noreferrer">^{<cd2>}</a>比较(小于)</li>
<li>列的更改顺序</li>
<li>累计和列-第一个<code>True</code>获取<code>1</code></li>
<li>通过<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.eq.html" rel="nofollow noreferrer">^{<cd6>}</a>与{<cd4>}比较</li>
</ul>
<hr/>
<pre><code>mask = df.drop('value',axis=1)
.lt(df['value'], axis=0)
.reindex(columns=['high','middle','low'])
.cumsum(axis=1)
.eq(1)
</code></pre>
<p>如果列<code>high</code>、<code>middle</code>和<code>low</code>中的所有值都是<code>False</code>,那么一定的正确性是必要的。我通过反转<code>mask</code>和<code>all</code>创建新列。在</p>
^{pr2}$
<p>最后一次呼叫<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.idxmax.html" rel="nofollow noreferrer">^{<cd13>}</a>:</p>
^{3}$
<p>以多个<a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.where.html" rel="nofollow noreferrer">^{<cd14>}</a>为尖<a href="https://stackoverflow.com/questions/42253069/categorizing-pandas-column-with-the-indiviual-custom-bins-tresholds#comment71664321_42253069">Paul H</a>的解决方案:</p>
<pre><code>df['category'] = np.where(df['high'] < df['value'], 'high',
np.where(df['middle'] < df['value'], 'medium',
np.where(df['low'] < df['value'], 'low', 'below_low')))
print (df)
value low middle high category
0 179.69 17.42 88.87 239.85 high
1 2.58 17.81 93.37 236.58 below_low
2 1.21 0.05 0.01 0.91 high
3 1.66 0.20 0.32 4.57 medium
4 3.54 0.04 0.04 0.71 high
5 5.97 0.16 0.17 2.55 high
6 5.39 0.86 1.62 9.01 medium
7 1.20 0.03 0.01 0.31 high
8 3.19 0.08 0.01 0.45 high
9 0.02 0.03 0.01 0.10 medium
10 3.98 0.18 0.05 0.83 high
11 134.51 78.63 136.86 478.27 low
12 254.53 83.73 146.33 486.65 medium
13 15.36 86.07 13.74 185.16 medium
14 85.10 86.12 13.74 185.16 medium
15 15.12 1.37 6.09 30.12 medium
</code></pre>