[英]Pandas dataframe group by column and apply min, max, average on different columns
I am looking a way to transform this dataframe below我正在寻找一种方法来转换下面的这个 dataframe
itemid clock value_min value_avg value_max item_type
A1 27/05/2021 4 7 38 cpu
A2 27/05/2021 4 5 15 mem
B1 27/05/2021 1 2 5 cpu
B2 27/05/2021 3 20 86 mem
A1 28/05/2021 8 8 9 cpu
A2 28/05/2021 1 2 5 mem
B1 28/05/2021 0 1 2 cpu
B2 28/05/2021 4 7 8 mem
to至
itemid value_min value_avg value_max item_type
A1 4 7,5 38 cpu
A2 1 3,5 15 mem
B1 0 0,5 5 cpu
B2 3 3,5 86 mem
I want to group by itemid and then apply the rules我想按 itemid 分组,然后应用规则
this should answer your question:这应该回答你的问题:
df = df.groupby('itemid').agg({'value_min': 'min', 'value_avg': 'mean', 'value_max': 'max', 'item_type': 'first'})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.