# `Spatex.Explorer`
[🔗](https://github.com/CountlinkX-Solutions/spatex/blob/v0.2.1/lib/spatex/explorer.ex#L1)

Per-site results as `Explorer.DataFrame`s.

`to_dataframe/2` turns a local ESDA result (`Spatex.ESDA.MoranLocal`,
`Spatex.ESDA.GLocal`, and any other result struct whose per-site fields are lists with one
entry per site), a `Spatex.Classify` result or a `Spatex.Region` result into a dataframe
with one row per site.
Explorer is an optional dependency: it is only touched when this module is called, through
runtime dispatch, so Spatex compiles and runs without it.

## Columns

Every field that is a list with one scalar per site becomes a column named after the field
(`is`, `q`, `z`, `lag`, `p_sim`, `gs`, `zs`, ...). Fields that are `nil` (for example
`p_sim` with `permutations: 0`), the simulation matrices (`sim`) and non-per-site fields are
skipped. In addition:

  * `id` - the graph node ids, first column, when the result carries them (ids that are not
    integers or strings are converted with `to_string/1`/`inspect/1`).
  * `cluster` - for `Spatex.ESDA.MoranLocal` with a `p_sim`, the quadrant label from
    `Spatex.ESDA.MoranLocal.cluster_labels/2`.
  * `yb` - for `Spatex.Classify`, the class of each observation.
  * `labels` - for the `Spatex.Region` results (`Skater`, `Ward`, `RegionKMeans`, `AZP`,
    `MaxP`), the region of each area; the only column. `nil` (areas `Spatex.Region.max_p/3`
    dropped) becomes a missing value.

Non-finite floats stay `:nan`, `:infinity` and `:neg_infinity`, which Explorer reads as
float special values.

## Options

  * `:crit` - significance level for the `cluster` column (default `0.05`).

## Examples

    iex> g = Spatex.Graph.from_arrays([0, 1, 1, 2, 2, 3], [1, 0, 2, 1, 3, 2])
    iex> m = Spatex.ESDA.moran_local([1, 5, 2, 8], g, permutations: 0)
    iex> df = Spatex.Explorer.to_dataframe(m)
    iex> Explorer.Series.to_list(df["q"])
    [2, 4, 2, 4]

# `to_dataframe`

```elixir
@spec to_dataframe(struct(), keyword()) :: struct()
```

Converts a per-site result to an `Explorer.DataFrame`. See the module documentation.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
