pandas 中有没有一种方法可以将一列聚合为平均值,将另一列聚合为计数?

Is there a way in pandas to aggregate one column as mean, and another as count?

我在任何地方都找不到解决方案。我想要实现的是: dataframe'Machine' 列分组,接下来是平均列 'datetime' 和最后一个计数 'Barcode'.

尝试失败:

 result = df.groupby('Machine')['datetime'].aggregate('mean')['Barcode'].aggregate('count')

[1]: https://i.stack.imgur.com/h8HiV.png <-- dateFrame before operation

df.groupby(['Machine']).agg({'datetime':'mean', 'Barcode': 'count'})