468,294 Members | 1,893 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,294 developers. It's quick & easy.

How can I use aggregate function to get avg, min and max grouped by id?

I have a document with id, timestamp and a value field. How can I use aggregate function to get avg, min and max grouped by id and everyday? Here’s the snippet I am using. The snippet has a flaw that it use timestamp and not the date part from the timestamp. Any help would be appreciated much.

document = db_collection.aggregate(
{
"$group": {"_id": {"$device_id"},
"timestamp": {"$timestamp"},
"average": {"$avg": "$value"},
"minimum": {"$min": "$value"},
"maximum": {"$max": "$value"}
}
}
)
4 Weeks Ago #1
1 3802
sambutle
1 Bit
If you are using Pandas DataFrame groupby[ use agg() ...

df.groupby(['Age'])['Height'].agg([('MaxValue','max'),('MinValue','min')])
2 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Najib Abi Fadel | last post: by
3 posts views Thread by Raghu | last post: by
4 posts views Thread by shapper | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.