where the column name can be a single column name,Can also be an array containing multiple column names
After the column names become groupedindex行索引的名字
as_index設成False的時候,Disable grouping key as row index
A dictionary or a dict that can match values up the grouping axis to the grouping nameSeries
Series
字典
The keys in the dictionary do not need to contain all of themindex,也可以包含indexkey not in
A list or array of values of the same length as the axis to be grouped
When using a list of values,分組的indexNo more default names
A function that can be called on the axis index or on a single label within the index
作為分組鍵傳遞的函數將會按照每個索引值調用一次,同時返回值會被用作分組名稱.
groupby().get_group()
pandas按照列groupby後,You can take the corresponding value according to the valuegroup. When done on multiple columnsgroupby時,get_groupWhen you need to enter multiple columns of valuestuple,比如get_group((‘a’, 1)),其中’a’為第一個groupa value in the column,1為第二個groupa value in the column.
import pandas as pd
df = pd.DataFrame({
'col1':['a', 'b', 'c','a', 'b', 'c'], 'col2':[1,2,3,4,5,6]})
df
>>> col1 col2
0 a 1
1 b 2
2 c 3
3 a 4
4 b 5
5 c 6
df.groupby('col1').get_group('a')
>>> col1 col2
0 a 1
3 a 4
df.groupby(['col1', 'col2']).get_group(('a', 1))
>>> col1 col2
0 a 1