# Pivoting/Group By

## What is a pivot table?

A pivot table is a method of aggregating a dataframe within one or more discrete categories you create. This aggregation might include sums, averages, or other statistics, which the pivot table groups together using a chosen aggregation function applied to the grouped values.

If you're used to doing "group bys" in Pandas, or using Excel Pivot Tables, then you're looking for Pivoting in Mito!

## Creating a pivot table

* Click on the `Pivot` icon in the `Home` tab of the Mito toolbar.
* Add a column to the `Rows` section to construct a key to group the dataframe by.
  * Optionally, to stratify the groups into individual cells, add a column to the `Columns` section.
* Add a column to the the `Values` section to aggregate data within the buckets defined by `Rows` and `Columns` above.
  * Optionally, switch the aggregation method of the column in the `Values` section.
* Optionally, add and configure `Filters` on the pivot table. Notably, these filters are applied to the source dataset before it is pivoted.&#x20;

<figure><img src="/files/BIH4EQPhJVwZl4EUSLyU" alt=""><figcaption></figcaption></figure>

### Group Dates within in Pivot Tables

If you're aggregating based on a `datetime` column (aka: you have a `datetime` column in either the `Rows` or `Columns` section), you can select how to group the date.&#x20;

By default, Mito will group dates by exact time. This means that two rows will be put in the same bucket within the pivot table if the `datetime` column matches to the exact second.&#x20;

However, if you wish to aggregate based on the `year`, then you can change the `group date by` to `year`. This will ignore months, days, minutes, and seconds, and combine all rows in the same year into the same bucket. Create a pivot table to explore all the ways to group dates.

{% hint style="info" %}
If the `group date by` option does not appear after adding a column to the Rows or Columns section of a pivot table, ensure that you have changed the dtype of that column to a `datetime` first.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.trymito.io/how-to/pivot-tables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
