<p>如果传递一个序列,我不会遇到使用<code>qcut()</code>的问题。我假设你的数据看起来像我正在使用的数据</p>
<pre><code>import pandas as pd
import numpy as np
data = {'values':np.random.randint(1,30,size=1000)}
df = pd.DataFrame(data)
df['ranks'] = pd.qcut(df['values'],10,labels=False)
print(df)
</code></pre>
<p>输出:</p>
<pre><code> values ranks
0 18 5
1 22 7
2 5 1
3 12 3
4 14 4
.. ... ...
995 22 7
996 13 4
997 26 8
998 3 0
999 22 7
</code></pre>
<p>之后,您可以使用<code>groupby()</code>或其他一组函数检查简单操作(例如箱子的限制):</p>
<pre><code>df_info = df.groupby('ranks').agg(
min_score=pd.NamedAgg(column='values',aggfunc='min'),
max_score=pd.NamedAgg(column='values',aggfunc='max'),
count_cases=pd.NamedAgg(column='values',aggfunc='count'))
print(df_info)
</code></pre>
<p>输出:</p>
<pre><code> min_score max_score count_cases
ranks
0 1 3 137
1 4 5 72
2 6 8 105
3 9 11 96
4 12 14 98
5 15 17 107
6 18 20 91
7 21 23 99
8 24 27 121
9 28 29 74
</code></pre>