今天在学习时,看到一个数据类型叫“SeriesGroupBy”,并且看到这样一个示例:
>>> s = pd.Series([1, 2, 3, 4])
>>> s
0 1
1 2
2 3
3 4
dtype: int64
>>> s.groupby([1, 1, 2, 2]).min()
1 1
2 3
第一次见到一维数组的分组,而且groupby后的参数还是一个列表,列表中还是4个值,这些列表中的数值都有什么作用?百度了一下没有查到,于是准备用最笨的方法——逐一修改参数,调试一下。详细记录如下:
第一组测试:修改一个参数1)修改第一个参数:>>>print( list( s.groupby([1, 1,1, 1]) ) )
[(1, 0 1
1 2
2 3
3 4
>>>print( list( s.groupby([2, 1,1, 1]) ) )
[(1, 1 2
2 3
3 4
dtype: int64),
(2, 0 1
>>>print( list( s.groupby([3, 1,1, 1]) ) )
[(1, 1 2
2 3
3 4
dtype: int64),
(3, 0 1
>>>print( list( s.groupby([5, 1,1, 1]) ) )
[(1, 1 2
2 3
3 4
dtype: int64),
(5, 0 1
【总结】
>>> print( list( s.groupby([1, 2, 1, 1]) ) )
[(1, 0 1
2 3
3 4
dtype: int64),
(2, 1 2
>>> print( list( s.groupby([1, 4, 1, 1]) ) )
[(1, 0 1
2 3
3 4
dtype: int64),
(4, 1 2
>>> print( list( s.groupby([1, 6, 1, 1]) ) )
[(1, 0 1
2 3
3 4
dtype: int64),
(6, 1 2
【总结】
>>> print( list( s.groupby([2, 2, 1, 1]) ) )
[(1, 2 3
3 4
dtype: int64),
(2, 0 1
1 2
>>> print( list( s.groupby([2, 3, 1, 1]) ) )[(1, 2 3
3 4
dtype: int64),
(2, 0 1
dtype: int64),
(3, 1 2
【总结】
其实看图比看文字更清楚,我个人总结的不够好!但我理解了。