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

Viewed 40

I cannot find solutions to that anywhere. What I am trying to achieve is: dataframe grouped by 'Machine' column, next would be average column 'datetime' and last one as a count of 'Barcode'.

Not working attempt:

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

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

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