Skip to content

Commit

Permalink
Adds new pages to tables chapter. (#516)
Browse files Browse the repository at this point in the history
## Description

Adds two new pages to the tables chapter that describe creating and
managing tables.

## Ticket

- Closes [DOCS-803](https://wandb.atlassian.net/browse/DOCS-803)
- Related to DOCS-814 (doesn't close)

## Checklist

Check if your PR fulfills the following requirements. Put an `X` in the
boxes that apply.

- [x] Files I edited were previewed on my local development server with
`yarn start`. My changes did not break the local preview.
- [x] Build (`yarn docusaurus build`) was run locally and successfully
without errors or warnings.
- [x] I merged the latest changes from `main` into my feature branch
before submitting this PR.


[DOCS-803]:
https://wandb.atlassian.net/browse/DOCS-803?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Noah Luna <[email protected]>
Co-authored-by: John Mulhausen <[email protected]>
  • Loading branch information
3 people authored Oct 3, 2024
1 parent 9a60c74 commit c800259
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 3 deletions.
87 changes: 87 additions & 0 deletions docs/guides/tables/tables-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
description: Create tables with W&B.
displayed_sidebar: default
---

# Create a table

Unlike traditional spreadsheets, Tables support numerous types of data. This includes
scalar values, strings, NumPy arrays, and most subclasses of `wandb.data_types.Media`.
You can embed `Images`, `Video`, `Audio`, and other sorts of rich, annotated media
directly in Tables, alongside other traditional scalar values.

Construct tables with initial data by creating a dataframe:


```python
import pandas as pd
import wandb

#Intialize the data
data = {"users": ["geoff", "juergen", "ada"], "feature_01": [1, 117, 42]}
#Turn the data into a dataframe.
df = pd.DataFrame(data)

tbl = wandb.Table(data=df)
assert all(tbl.get_column("users") == df["users"])
assert all(tbl.get_column("feature_01") == df["feature_01"])
```
## Add data

Add data to Tables incrementally by using the
`add_data`, `add_column`, and `add_computed_column` functions for
adding rows, columns, and columns computed from data in other columns, respectively:


```python
import wandb

tbl = wandb.Table(columns=["user"])

users = ["geoff", "juergen", "ada"]

[tbl.add_data(user) for user in users]
assert tbl.get_column("user") == users


def get_user_name_length(index, row):
return {"feature_01": len(row["user"])}


tbl.add_computed_columns(get_user_name_length)
assert tbl.get_column("feature_01") == [5, 7, 3]
```

## Log data

Log tables directly to runs with `run.log({"my_table": table})`
or add them to artifacts using `artifact.add(table, "my_table")`:


```python
import numpy as np
import wandb

wandb.init()

tbl = wandb.Table(columns=["image", "label"])

images = np.random.randint(0, 255, [2, 100, 100, 3], dtype=np.uint8)
labels = ["panda", "gibbon"]
[tbl.add_data(wandb.Image(image), label) for image, label in zip(images, labels)]

wandb.log({"classifier_out": tbl})
```

Tables added directly to runs produces a corresponding Table Visualizer in the
Workspace which can further analyze data and export it to reports.

Tables added to artifacts appear in the Artifact tab and render
an equivalent Table Visualizer directly in the artifact browser.

## Best practices
Tables expect each value for a column to be of the same type. By default, a column supports optional values, but not mixed values. If you absolutely need to mix types, you can enable the `allow_mixed_types` flag which turns off type checking on the data. This results in some table analytics features turning off due to lack of consistent typing.

## Next steps
- For more information about visualizing tables, see the [table visualization guide](./visualize-tables.md).
- For a more in-depth walkthrough of how to use tables, see the [walkthrough](tables-walkthrough.md).
6 changes: 3 additions & 3 deletions docs/guides/tables/tables-download.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: How to export data from tables.
description: Export data from tables.
displayed_sidebar: default
title: Export table data
---

Like all W&B Artifacts, Tables can be converted into pandas dataframes for easy data exporting.

## Convert `table` to `artifact`
First, you'll need to convert the table to an artifact. The easiest way to do this using `artifact.get(table, "table_name")`:
First, convert the table to an artifact. The easiest way to do this using `artifact.get(table, "table_name")`:

```python
# Create and log a new table.
Expand All @@ -34,7 +34,7 @@ df = table.get_dataframe()
```

## Export Data
Now you can export using any method dataframe supports:
Next, export using any method dataframe supports:

```python
# Converting the table data to .csv
Expand Down
37 changes: 37 additions & 0 deletions docs/guides/tables/tables-navigate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
description: How to use the W&B platform to manage tables.
displayed_sidebar: default
---

# Manage Tables

Once you've [created a table](./tables-create.md), you can use the W&B platform to analyze, customize, and manage your data.

## The W&B Platform
When you first open your workspace, you will be presented with a simple visualization of your tables. Each table you create appears in a `panel` where you can further customize your data.

You'll also notice a statement at the top of your panel. If you're following one of our example guides, it will look something like `runs.summary["Table Name"]`. You can edit this statement, which will be discussed later.

In a default scenario, your table will display all of your runs, with each run having its own color so you can easily differentiate them.

### Format Tables


## Run Commands
Clicking on the funnel icon will bring up the filter menu. This will allow you to run various commands to filter your data. For example, if you wanted to only show columns that were alphanumeric, you could write something like `row["a"].isAlnum`.

Currently, you can filter by:
- index
- project
- row
- range

For more information on visualizing tables, see our [full guide](./visualize-tables.md).

## Export Data
You can easily export your table data to a .csv file by clicking the `Export to CSV` button, usually located at the bottom of a table's panel. Clicking this button automatically downloads a .csv file of your current table, with any formats or editing you have made.

For more methods of exporting data, see our [full guide](./tables-download.md).

## Next Steps
For a more in-depth walkthrough of how to use tables, see our [walkthrough](tables-walkthrough.md).
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
description: How to create tables.
displayed_sidebar: ja
---

# Create a Table

Unlike traditional spreadsheets, Tables support numerous types of data:
scalar values, strings, numpy arrays, and most subclasses of `wandb.data_types.Media`.
This means you can embed `Images`, `Video`, `Audio`, and other sorts of rich, annotated media
directly in Tables, alongside other traditional scalar values.

Tables can be constructed with initial data using the `data` or
`dataframe` parameters:


```python
import pandas as pd
import wandb

data = {"users": ["geoff", "juergen", "ada"], "feature_01": [1, 117, 42]}
df = pd.DataFrame(data)

tbl = wandb.Table(data=df)
assert all(tbl.get_column("users") == df["users"])
assert all(tbl.get_column("feature_01") == df["feature_01"])
```
## Add Data

You can add data to Tables incrementally by using the
`add_data`, `add_column`, and `add_computed_column` functions for
adding rows, columns, and columns computed from data in other columns, respectively:


```python
import wandb

tbl = wandb.Table(columns=["user"])

users = ["geoff", "juergen", "ada"]

[tbl.add_data(user) for user in users]
assert tbl.get_column("user") == users


def get_user_name_length(index, row):
return {"feature_01": len(row["user"])}


tbl.add_computed_columns(get_user_name_length)
assert tbl.get_column("feature_01") == [5, 7, 3]
```

## Log Data

Tables can be logged directly to runs using `run.log({"my_table": table})`
or added to artifacts using `artifact.add(table, "my_table")`:


```python
import numpy as np
import wandb

wandb.init()

tbl = wandb.Table(columns=["image", "label"])

images = np.random.randint(0, 255, [2, 100, 100, 3], dtype=np.uint8)
labels = ["panda", "gibbon"]
[tbl.add_data(wandb.Image(image), label) for image, label in zip(images, labels)]

wandb.log({"classifier_out": tbl})
```

Tables added directly to runs as above will produce a corresponding Table Visualizer in the
Workspace which can be used for further analysis and exporting to reports.

Tables added to artifacts can be viewed in the Artifact Tab and will render
an equivalent Table Visualizer directly in the artifact browser.

## Best Practices
Tables expect each value for a column to be of the same type. By default, a column supports optional values, but not mixed values. If you absolutely need to mix types, you can enable the `allow_mixed_types` flag which will disable type checking on the data. This will result in some table analytics features being disabled due to lack of consistent typing.

## Next Steps
- For more information about visualizing tables, see our [table visualization guide](./visualize-tables.md).
- For a more in-depth walkthrough of how to use tables, see our [walkthrough](tables-walkthrough.md).
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
description: How to use the W&B platform to manage tables.
displayed_sidebar: ja
---

# Manage Tables

Once you've [created a table](./tables-create.md), you can use the W&B platform to analyze, customize, and manage you data.

## The W&B Platform
When you first open your workspace, you will be presented with a simple visualization of your tables. Each table you create appears in a `panel` where you can further customize your data.

You'll also notice a statement on the top of your panel. If you're following one of our example guides, it will look something like `runs.summary["Table Name"]`. You can edit this statement, which will be discussed later.

In a default scenario, your table will display all of your runs, with each run having its own color so you can easily differentiate them.

## Run Commands
Clicking on the funnel icon will bring up the filter menu. This will allow you to run various commands to filter your data. For example, if you wanted to only show columns that were alphanumeric, you could write something like `row["a"].isAlnum`.

Currently, you can filter by:
- index
- project
- row
- range

For more information on visualizing tables, see our [full guide](./visualize-tables.md)

## Export Data
You can easily export your table data to a .csv file by clicking the `Export to CSV` button, usually located at the bottom of a table's panel. Clicking this button automatically downloads a .csv file of your current table, with any formats or editing you have made.

For more methods of exporting data, see our [full guide](./tables-download.md).

## Next Steps
For a more in-depth walkthrough of how to use tables, see our [walkthrough](tables-walkthrough.md).
2 changes: 2 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ export default {
label: 'Tables',
link: {type: 'doc', id: 'guides/tables/intro'},
items: [
'guides/tables/tables-create',
'guides/tables/tables-navigate',
'guides/tables/tables-walkthrough',
'guides/tables/visualize-tables',
'guides/tables/tables-gallery',
Expand Down

0 comments on commit c800259

Please sign in to comment.