Iterating through grouped data
In this section, we will see how to access grouped data based on grouped keys, loop through this grouped data, and perform data aggregation operations on it.
Iterating through single- and double-column grouped data
In this section, we will see how Danfo.js provides the means of iterating through each of the groups created during the groupby
operations. This data is grouped by the keys contained in the groupby
column.
The keys are stored as a dictionary or object in a class attribute called data_tensors
. This object contains the grouped key as its keys and also stores the DataFrame data associated with the keys as the object values.
Using the previous DataFrame, let's group by column A
and then iterate through data_tensors
:
let group_df = df.groupby([ "A"]); console.log(group_df.data_tensors)
We group the DataFrame by column A
and then print out data_tensors,
as shown in the following screenshot: