> For the complete documentation index, see [llms.txt](https://www.csvpath.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.csvpath.org/getting-started/the-flightpath-data-examples/math/averaging-across-groups.md).

# Averaging across groups

{% hint style="success" %}
Run this example using its test data from within [FlightPath Data](https://www.flightpathdata.com/).
{% endhint %}

```
~
  This csvpath finds the average temp for all days sampled in each month.
  The result is a "month_ave" dictionary with an average temp keyed by
  each observed month number.

  I.e. for the first three months of the year you might see:
	{'01': 27.25, '02': 34.25, '03': 39.65}

  While this kind of pivot may be useful, it's worth pointing out that
  CsvPath Framework's goal is to assess the validity of data and upgrade
  it, if needed, to ideal-form raw data. Analysis and reporting are
  valuable, but ancillary.

  test-data: temps.txt
~
$[1*][
	~ find the month number ~
	@month = regex(/[0-9]{4}-([0-9]{1,2})/, #0, 1)

	~ count the number of samples we have for the month ~
	tally.month_obs(@month)

	~ get a subtotal of the month's temps ~
	@sub = subtotal.month_temp(@month, #temp)

	~ get the count of observations in month ~
	@obs = get("month_obs_month",@month)

	~ get the average for the month ~
	@ave = divide(@sub, @obs)

	~ store the average ~
	put("month_ave", @month, @ave)

print("
   temp: $.headers.temp
   obs: $.variables.obs
   average: $.variables.ave
   month_temp: $.variables.month_temp
   month_ave: $.variables.month_ave
")
]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://www.csvpath.org/getting-started/the-flightpath-data-examples/math/averaging-across-groups.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.
