Skip to content
Advertisement

How to group data from a list of namedtuples

In python, I have the following data in a list of namedtuple in memory:

JavaScript

I want to group the data by :

  • cluster
  • cluster and host
  • cluster and host and database
  • cluster and host and database and diskgroup

I won’t need the disk details.

In each group I want to :

  • sum the values of read_bytes_per_sec and write_bytes_per_sec
  • compute the average of the values of avg_ms_per_read and avg_ms_per_write

As a result I want a list containing :

JavaScript

result may be a list of dict or list of namedtuple I guess. the order in the final list does not matters. I’m using python 3.8.

Any Ideas? Thanks

Advertisement

Answer

These are pandas data frames, if you need python dictionary version you’ll get it by adding .to_dict() to per_diskgroup, per_database, per_host, per_cluster. eg: per_database.to_dict()

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement