Skip to content

Logging structured data

Comet's table allow you to log any structured data, except for datasets which should be logged as Artifacts that can be shared between experiments.

Example of Data Panel
Example of logged table displayed in the Comet UI

You can use Comet's table to access and visualize tabular data, logged from a Pandas dataframe (in the .json, .csv, .md, or .html format) or from a file path (with the .csv or .tsv extension).

The following method can be used to log tables:

The following panel can be used to visualize tables:

In addition all the tables logged to an Experiment can be view in the Single Experiment page tab:

For example, you could...

Log an evaluation report and analyze it to identify specific areas where the model excels or struggles, guiding further optimization efforts or informing stakeholders about the model's performance characteristics.

Log a Pandas dataframe

The example below showcases how to log a Pandas dataframe as a table in Comet.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import comet_ml
import pandas as pd

# Initialize the Comet Experiment
comet_ml.init()
exp = comet_ml.Experiment()

# Create an example dataframe
df = pd.DataFrame(
    {
        "week": ["week 1", "week 2", "week 3"],
        "accuracy": [0.85, 0.92, 0.88],
        "loss": [0.3, 0.2, 0.25]
    }
)

# Log the dataframe to Comet
exp.log_table(filename="example_table_from_df.csv", tabular_data=df)

When tabular_data is provided, the headers are automatically read from the Pandas dataframe but you can change the headers argument to False to ignore them or also provide a list of new headers.

Additionally, you can pass any format kwargs supported by Pandas for the specified format (e.g., you can refer to pandas.DataFrame.to_json() for a dataframe in the .json format).

Log a .csv file

The example below showcases how to upload a .csv file as a table in Comet.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import comet_ml
import pandas as pd

# Initialize the Comet Experiment
comet_ml.init()
exp = comet_ml.Experiment()

# Create an example .csv file
with open("/tmp/example_table_from_file.csv", "w+") as f:
    f.write("week, accuracy, loss\n")
    f.write("0.85, 0.92, 0.88\n")
    f.write("0.3, 0.2, 0.25\n")

# Log the table to Comet
exp.log_table(filename="/tmp/example_table_from_file.csv")

Additionally, you can specify the headers argument to provide a list of headers.

May. 17, 2024