Python 如何使用pandas.cut对我的数据进行分组?
如何使用pandas.cut将我的数据分组并以以下格式输出为pandas.DataFramePython 如何使用pandas.cut对我的数据进行分组?,python,pandas,Python,Pandas,如何使用pandas.cut将我的数据分组并以以下格式输出为pandas.DataFrame raw_data=''' 82 68 86 94 89 63 77 76 84 89 75 78 81 82 76 99 80 84 89 88 60 83 72 83 85 56 86 68 75 100 90 84 75 86 74 77 95 63 80
raw_data='''
82 68 86 94 89 63 77 76 84 89
75 78 81 82 76 99 80 84 89 88
60 83 72 83 85 56 86 68 75 100
90 84 75 86 74 77 95 63 80 76
100 43 76 81 79 74 96 52 69 86'''
您可以
剪切
,然后调用描述
:
interval numbers
1 (0,60] 4
2 (60,70] 5
3 (70,80] 16
4 (80,90] 19
5 (90,100] 6
或者如果你非常挑剔:
>>> nums = pd.Series(raw_data.split(), dtype=int)
>>> ncut = pd.cut(nums, [0, 60, 70, 80, 90, 100])
>>> d = ncut.describe()
>>> d
counts freqs
levels
(0, 60] 4 0.08
(60, 70] 5 0.10
(70, 80] 16 0.32
(80, 90] 19 0.38
(90, 100] 6 0.12
[5 rows x 2 columns]
您可以
剪切
,然后调用描述
:
interval numbers
1 (0,60] 4
2 (60,70] 5
3 (70,80] 16
4 (80,90] 19
5 (90,100] 6
或者如果你非常挑剔:
>>> nums = pd.Series(raw_data.split(), dtype=int)
>>> ncut = pd.cut(nums, [0, 60, 70, 80, 90, 100])
>>> d = ncut.describe()
>>> d
counts freqs
levels
(0, 60] 4 0.08
(60, 70] 5 0.10
(70, 80] 16 0.32
(80, 90] 19 0.38
(90, 100] 6 0.12
[5 rows x 2 columns]
我认为这将是对文档的一个很好的补充,因为我没有找到它(或者我搜索得不够好)。例如,这里解释了
cut
,没有提到descripe
。我认为这将是对文档的一个很好的补充,因为我没有找到它(或者我搜索得不够好)。例如,这里解释了cut
,而没有提到descripe
。