# Variable

## *class* <mark style="color:purple;">Variable</mark>

Variables represent the "columns" in tables (and uploads), and have certain metadata as well as detailed univariate summary statistics associated with them. Use this class to interface with variables and their metadata.

## Constructors

<table data-header-hidden><thead><tr><th width="342">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="query/query.list_variables"><strong><code>query.list_variables</code></strong></a>([max_results])</td><td>List all variables in a (completed) query's results.</td></tr><tr><td><a href="table/table.list_variables"><strong><code>table.list_variables</code></strong></a>([max_results])</td><td>List all variables in a table.</td></tr><tr><td><a href="upload/upload.list_variables"><strong><code>upload.list_variables</code></strong></a>([max_results])</td><td>List all variables in a (completed) upload.</td></tr><tr><td><a href="query/query.variable"><strong><code>query.variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within a query's results based on its (case-insensitive) name.</td></tr><tr><td><a href="table/table.variable"><strong><code>table.variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within a table based on its (case-insensitive) name.</td></tr><tr><td><a href="upload"><strong><code>upload.variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within an upload based on its (case-insensitive) name.</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Basics" %}

<pre class="language-python"><code class="lang-python"><strong>table = redivis.organization("Demo").dataset("iris_species").table("iris")
</strong>
variable = table.variable("sepalLengthCm")

variable.exists() # -> True
variable.get(wait_for_statistics=True) 

print(variable.properties)

{
"kind": "variable",
... (see variable resource definition)
}

print(variable.get_statistics())
{
  "kind": "variableStatistics"
  "status": "completed",
  "count": 150,
  "numDistinct": 35,
  "min": 4.3,
  "max": 7.9,
  "mean": 5.8433333333333355,
  "approxMedian": 0.8280661279778625,
  ...
}
</code></pre>

{% endtab %}
{% endtabs %}

## Attributes

| **`properties`** | A dict containing the [API resource representation of the variable](https://docs.redivis.com/api/resource-definitions/variable#base-definition). This will only be populated after certain methods are called, particularly the `get` method, and will otherwise be `None`. |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`table`**      | A reference to the [Table](https://docs.redivis.com/api/client-libraries/redivis-python/reference/table) instance that constructed this variable. Will be `None` if the variable belongs to an upload.                                                                      |
| **`upload`**     | A reference to the [Upload](https://docs.redivis.com/api/client-libraries/redivis-python/reference/upload) instance that constructed this variable. Will be `None` if the variable belongs to a table.                                                                      |

## Methods

<table data-header-hidden><thead><tr><th width="421">Name</th><th>Description</th></tr></thead><tbody><tr><td><a href="variable/variable.get"><strong><code>variable.get</code></strong></a>()</td><td>Gets the variable, after which the <code>properties</code> attribute will be populated according to the <a href="../../../../resource-definitions/variable#get-definition">variable.get resource definition.</a></td></tr><tr><td><a href="variable/variable.get_statistics"><strong><code>variable.get_statistics</code></strong></a>()</td><td>Gets the variable statistics, returning a dict corresponding the <a href="../../../resource-definitions/variablestatistics">variableStatistics resource definition.</a></td></tr><tr><td><a href="variable/variable.exists"><strong><code>variable.exists</code></strong></a>()</td><td>List all visible datasets owned by the user.</td></tr><tr><td><a href="variable/variable.update"><strong><code>variable.update</code></strong></a>([*, label, description, ...])</td><td>Update a variable's metadata.</td></tr></tbody></table>
