table
table ¶
TableEntry
pydantic-model
¶
Bases: DataProduct
Defines an entry to be collected into a table.
Collected table entries will be printed in three forms when possible: melted, pivot (when possible), and stats (on pivot columns, when possible).
Attributes:
| Name | Type | Description |
|---|---|---|
tags |
Tags
|
Tags used to sort data products |
row |
float | str
|
Row Label |
col |
float | str
|
Column Label |
value |
float | str
|
Value |
unit |
str | None
|
Units for value |
metadata |
dict[str, str]
|
A dictionary of metadata to be used as a tool tip for mousover in grafana |
Show JSON schema:
{
"additionalProperties": false,
"description": "Defines an entry to be collected into a table.\n\nCollected table entries will be printed in three forms when possible: melted, pivot (when possible), and stats (on pivot columns, when possible).\n\nAttributes:\n tags (Tags): Tags used to sort data products\n row (float | str): Row Label\n col (float | str): Column Label\n value (float | str): Value\n unit (str | None): Units for value\n metadata (dict[str, str]): A dictionary of metadata to be used as a tool tip for mousover in grafana",
"properties": {
"tags": {
"items": {
"anyOf": []
},
"title": "Tags",
"type": "array"
},
"metadata": {
"additionalProperties": {
"type": "string"
},
"default": {},
"title": "Metadata",
"type": "object"
},
"row": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
}
],
"title": "Row"
},
"col": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
}
],
"title": "Col"
},
"value": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "boolean"
}
],
"title": "Value"
},
"unit": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Unit"
}
},
"required": [
"tags",
"row",
"col",
"value"
],
"title": "TableEntry",
"type": "object"
}
Config:
extra:'forbid'
Fields:
get_entry_dict ¶
Returns a dictionary of entries to be used in creating a table.
Returns:
| Type | Description |
|---|---|
dict[str, str | float]
|
Dictionary of entries to be used in creating a melted DataFrame |
Source code in src/trendify/api/formats/table.py
load_and_pivot
classmethod
¶
load_and_pivot(path: Path)
Loads melted table from csv and pivots to wide form.
csv should have columns named 'row', 'col', and 'value'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
path to CSV file |
required |
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
Pivoted data frame or elese |
Source code in src/trendify/api/formats/table.py
pivot_table
classmethod
¶
pivot_table(melted: DataFrame)
Attempts to pivot melted row, col, value DataFrame into a wide form DataFrame
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
melted
|
DataFrame
|
Melted data frame having columns named |
required |
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pivoted DataFrame if pivot works else |