I have a dataset, df, where I would like to group by a certain column and take the aggregates of other columns.
df
version host date name purpose date
pat A 12/1/2019 pat hi 12/1/2019
fam A 12/1/2019 fam cat 12/1/2019
set BB 12/2/2019 set hi 12/2/2020
ok BB 12/2/2019 ok hi 12/2/2020
sure BB 12/2/2019 sure cat 12/2/2020
DESIRED
version host date name purpose date
2 A 12/1/2019 2 2 12/1/2019
3 B 12/2/2019 3 3 12/2/2019
DOING
df.groupby['host].agg({'version' : 'count', 'name': 'count' , 'purpose': 'count'})
However, this is not giving me the count of the desired columns. Any suggestion is appreciated
question from:
https://stackoverflow.com/questions/65837176/group-by-and-aggregate-dataset-using-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…