Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Aggregate
#1
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 appcreciated much.

document = db_collection.aggregate(
    {
        "$group": {
            "_id": {"$device_id"},
            "timestamp": {"$timestamp"},
            "average": {"$avg": "$value"},
            "minimum": {"$min": "$value"},
            "maximum": {"$max": "$value"}
        }
    }
)
Reply
#2
This question is a bit vague in details of what aggregate is or where it comes from.
what is db_collection? its definition is not shown or the module it comes from is not stated.
Please see the How to ask Smart Questions link in my singnature
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python and pandas: Aggregate lines form Excel sheet Glyxbringer 12 1,836 Oct-31-2023, 10:21 AM
Last Post: Pedroski55
  df column aggregate and group by multiple columns SriRajesh 0 1,036 May-06-2022, 02:26 PM
Last Post: SriRajesh
  Python group by and aggregate dervast 1 1,572 Aug-27-2019, 12:12 PM
Last Post: ThomasL
  How to aggregate rows with same column Leoni 1 2,522 Jul-08-2018, 08:33 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020